Mastering Linux commands is essential for efficiently managing and automating tasks in a Linux environment. This cheat sheet provides a quick reference to commonly used commands, from basic file manipulations,networking, system monitoring and user management.
Whether you’re a beginner or an experienced user, these commands will help you work more effectively in the Linux shell.
File Management
| Command | Description |
| cat > file.txt | Create or overwrite contents of a file. |
| cat file.txt | View file content. |
| cat >> file.txt | Append content to a file. |
| touch file.txt | Create an empty file. |
| touch .hiddenfile | Create a hidden file. |
| touch file1.txt file2.txt | Create multiple files. |
| cp <source> <destination> | Copy files and directories. |
| mv <source> <destination> | Move or rename files and directories. |
| rm <file.txt> | Remove a file. |
| rm -rf <directory> | Remove a directory and its contents recursively. |
| ln -s <source> <target> | Create a symbolic link (soft link). |
| ln <source> <target> | Create a hard link. |
| sort <options> <file> | Sort file content. |
| cut -d: -f3 <file> | Retrieve a specific column from a file using a delimiter. |
Directory Management
| Command | Description |
| mkdir <directory> | Create a new directory. |
| mkdir -p <path> | Create a directory and any parent directories as needed. |
| ls <directory> | List directory contents. |
| ls -al | List all files, including hidden ones, in a long format. |
| pwd | Display the current directory path. |
| cd <directory> | Change the current directory. |
| cd ../ | Move one level up in the directory hierarchy. |
| rmdir <directory> | Remove an empty directory. |
Viewing and Editing Files
| Command | Description |
| less <file.txt> | View file content page by page. |
| head -n10 <file.txt> | View the first 10 lines of a file. |
| tail -n5 <file.txt> | View the last 5 lines of a file. |
| vim <file> | Edit a file using the Vim editor. |
| sed ‘s/old/new/g’ <file> | Search and replace text in a file. |
| grep <pattern> <file> | Search for a pattern in a file. |
| awk ‘/pattern/ {print $1}’ <file> | Pattern scanning and processing in files. |
| cat <file> | Concatenate and display file content. |
| tee <file> | Write output to a file and display it on the terminal. |
| uniq <file> | Remove duplicate lines from a file. |
File Compression
| Command | Description |
| gzip <file> | Compress a file. |
| gunzip <file> | Decompress a file. |
| tar -cvf <archive.tar> <files> | Create a tar archive. |
| tar -xvf <archive.tar> | Extract a tar archive. |
Process Management
| Command | Description |
| ps aux | Display detailed information about running processes. |
| top | Display real-time system stats, including process info. |
| kill <process_id> | Terminate a process by its ID. |
| history | Show command history. |
| chmod 755 <file> | Change file permissions. |
| chown user:group <file> | Change file ownership. |
Disk and File System
| Command | Description |
| df -h | Display disk space usage in human-readable format. |
| du -sh <directory> | Display the size of a directory. |
| mount | Mount a filesystem. |
| umount <device> | Unmount a filesystem. |
| lsblk | List information about block devices. |
User and Group Management
| Command | Description |
| useradd <username> | Create a new user. |
| usermod -l <newname> <oldname> | Change a username. |
| passwd <username> | Set or update a user’s password. |
| groupadd <groupname> | Create a new group. |
| gpasswd -M <users> <group> | Add multiple users to a group. |
| usermod -L <username> | Lock a user account. |
| usermod -U <username> | Unlock a user account. |
Networking and System Monitoring
| Command | Description |
| ifconfig | Display network interface information. |
| ping <hostname> | Test network connectivity. |
| nslookup <domain> | Get DNS information for a domain. |
| netstat -tuln | Show open ports and network connections. |
| hostname | Display or set the system’s hostname. |
| curl <url> | Download files or interact with APIs. |
| scp <file> <user@host:path> | Securely copy files to a remote system. |
| rsync -avz <source> <destination> | Sync files between two locations. |
Package Management (RPM/YUM)
| Command | Description |
| rpm -ivh <package.rpm> | Install an RPM package. |
| rpm -qa | List installed RPM packages. |
| yum install <package> | Install software via YUM. |
| yum update <package> | Update installed software. |
| yum remove <package> | Remove software via YUM. |
Scheduling and Automation
| Command | Description |
| crontab -e | Edit cron jobs for scheduling tasks. |
| crontab -l | List scheduled cron jobs. |
| systemctl start <service> | Start a system service. |
| systemctl stop <service> | Stop a system service. |
| systemctl status <service> | Check the status of a service. |
Security and Permissions
| Command | Description |
| chmod <permissions> <file> | Change file permissions (e.g., 755). |
| chown <user>:<group> <file> | Change file ownership. |
| ssh-keygen | Generate SSH key pairs. |
| ssh <user@hostname> | Connect to a remote system securely via SSH. |
| scp <file> <remote_host:path> | Securely copy files over SSH. |
This Linux Command Cheat Sheet provides a quick reference to some of the most commonly used commands in Linux. Use it to improve your productivity and manage Linux systems more effectively. For deeper exploration of these commands, check out the man pages (man <command>)