Mastering the command line is a key skill for anyone working with Linux, whether you're managing servers, developing software, or orchestrating containers. Linux commands offer powerful ways to interact with the system, automate tasks, and manage resources efficiently. This guide covers some of the most commonly used Linux commands that form the foundation of daily tasks in a Linux environment.
Basic Navigation and File Management Commands
ls - List Directory Contents
The ls command lists the files and directories in the current directory. It's often the first command you'll use when navigating the filesystem. Learn more about the Linux File System.
ls- Options:
cd - Change Directory
The cd command changes the current working directory, essential for navigating the Linux file system.
cd /path/to/directory- Shortcuts:
pwd - Print Working Directory
The pwd command shows the full path of the current working directory, helping you confirm your location in the directory structure.
pwdcp - Copy Files and Directories
The cp command copies files or directories from one location to another.
cp source_file destination_file- Options:
mv - Move or Rename Files and Directories
The mv command moves or renames files and directories.
mv old_name new_name- Use cases:
rm - Remove Files or Directories
The rm command deletes files or directories.
rm file_name- Options:
Caution: rm is irreversible, so use it carefully, especially with the -r option.
mkdir - Create Directories
The mkdir command creates new directories.
mkdir directory_name- Options:
rmdir - Remove Empty Directories
The rmdir command removes empty directories.
rmdir directory_nameFor removing directories with contents, use rm -r.
File Viewing and Editing Commands
cat - Concatenate and Display File Contents
The cat command displays the contents of a file.
cat file_name- Options:
less and more - View File Contents Page by Page
less and more allow you to view large files one page at a time.
less file_name- Navigation:
head and tail - View the Beginning or End of a File
head shows the first few lines of a file, while tail shows the last few lines.
head file_nametail file_name- Options:
nano and vim - Text Editors
nano and vim are command-line text editors. nano is more beginner-friendly, while vim offers powerful features for advanced users.
nano file_namevim file_nameLearn more about Shell Scripting Best Practices to enhance your editing and scripting skills in Linux.
System Monitoring and Management Commands
ps - Display Running Processes
The ps command displays currently running processes.
ps- Options:
top - Real-Time System Monitoring
top provides a real-time view of system processes, including CPU and memory usage.
top- Navigation:
htop - Interactive Process Viewer
htop is an enhanced version of top with a more user-friendly interface (requires installation on some systems).
htopdf - Disk Space Usage
The df command displays disk space usage for the file system.
df -h- Options:
du - Directory Space Usage
The du command estimates file and directory space usage.
du -h directory_name- Options:
free - Display Memory Usage
The free command shows the amount of free and used memory in the system.
free -h- Options:
File Permissions and Ownership Commands
chmod - Change File Permissions
The chmod command changes the permissions of a file or directory.
chmod 755 file_name- Common Permission Settings:
Learn more about Linux File Permissions to better understand how chmod works.
chown - Change File Ownership
The chown command changes the owner and group of a file or directory.
chown user:group file_nameNetworking Commands
ping - Test Network Connectivity
The ping command tests the network connection to a host.
ping example.com- Options:
ifconfig - Configure Network Interfaces
The ifconfig command configures or displays network interfaces.
ifconfig- Alternative:
Learn more about Linux Networking Commands for advanced networking tasks.
curl - Transfer Data from or to a Server
The curl command transfers data to or from a server, using various protocols like HTTP, FTP, and more.
curl http://example.com- Options:
wget - Download Files from the Web
wget is a command-line utility to download files from the web.
wget http://example.com/file.zip