Linux Commands Cheat Sheet
File Management
1. ls – List directory contents
o Example: ls -l → Long listing with details.
2. cd – Change directory
o Example: cd /home/swapna → Move to /home/swapna.
3. pwd – Print working directory
o Example: pwd → Shows /home/zaib.
4. cp – Copy files or directories
o Example: cp [Link] /tmp → Copy [Link] to /tmp.
5. mv – Move or rename files or directories
o Example 1: mv [Link] [Link] → Rename file.
o Example 2: mv [Link] /tmp → Move to /tmp.
6. rm – Remove files or directories
o Example 1: rm [Link] → Remove file.
o Example 2: rm -rf /tmp/old_directory → Remove directory and contents.
7. touch – Create a new empty file
o Example: touch [Link] → Creates an empty file.
8. mkdir – Create a new directory
o Example: mkdir new_folder → Create folder.
9. rmdir – Remove an empty directory
o Example: rmdir new_folder → Remove empty folder.
10. cat – Display file contents
o Example: cat [Link] → Show contents of file.
11. head – Show first lines of a file
o Example: head -n 5 [Link] → Show first 5 lines.
12. tail – Show last lines of a file
o Example: tail -n 5 [Link] → Show last 5 lines.
13. chmod – Change file permissions
o Example: chmod 755 [Link] → Give owner full, others read/execute.
14. chown – Change file ownership
o Example: sudo chown newuser [Link] → Make newuser the owner.
15. find – Search for files
o Example: find /home -name [Link] → Search [Link] in /home.
16. locate – Find files by name
o Example: locate [Link] → Find all paths containing [Link].
17. grep – Search text by pattern
o Example: grep "error" [Link] → Find “error” in logfile.
18. diff – Compare files line by line
o Example: diff [Link] [Link] → Show differences.
19. tar – Archive files
o Example: tar -cvf [Link] /home/user/ → Create archive.
o Example: tar -xvf [Link] → Extract archive.
20. zip – Compress files
o Example: zip [Link] [Link] [Link]
o Example: unzip [Link] → Extract.
System Monitoring and Networking Commands
1. top – Display running processes
o Example: top → Shows CPU, memory, and running processes.
2. htop – Interactive process viewer
o Example: htop → Colorful, interactive version of top.
3. ps – Show processes
o Example: ps aux | grep nginx → Find nginx process.
4. df – Show disk usage
o Example: df -h → Show disk space in human-readable format.
5. du – Show directory space usage
o Example: du -sh /var/log → Total size of /var/log.
6. free – Show memory usage
o Example: free -m → Show memory in MB.
7. uptime – Show system uptime
o Example: uptime → Prints how long system has been running.
8. uname – Show system information
o Example: uname -a → Full system details (kernel, architecture).
9. whoami – Show current user
o Example: whoami → Prints username of logged-in user.
10. lsof – List open files
o Example: lsof -i :80 → Show processes using port 80.
11. vmstat – Virtual memory stats
o Example: vmstat 2 → Updates memory/CPU stats every 2 sec.
12. iostat – I/O stats
o Example: iostat -x 2 → Extended disk I/O every 2 sec.
13. netstat – Network connections and routing
o Example: netstat -tulnp → Show listening ports and programs.
14. ifconfig – Network interface details
o Example: ifconfig eth0 → Show details of eth0.
15. ping – Test connectivity
o Example: ping [Link] → Send packets to [Link].
16. traceroute – Track packet route
o Example: traceroute [Link] → Show hops from you to [Link].
3. Package Management (Ubuntu/Debian)
1. sudo apt-get update – Update package lists
Example: sudo apt-get update → Refresh list of available packages.
2. sudo apt-get upgrade – Upgrade all packages
Example: sudo apt-get upgrade → Install latest versions of all installed packages.
3. sudo apt-get install <pkg> – Install a package
Example: sudo apt-get install nginx → Install NGINX web server.
4. sudo apt-get remove <pkg> – Remove a package
Example: sudo apt-get remove nginx → Uninstall NGINX but keep config files.
5. dpkg – Manage individual .deb packages
Example: sudo dpkg -i [Link] → Install a .deb file manually.
Example: sudo dpkg -r package-name → Remove a .deb package.
User & Permission Management
useradd – Add user.
o sudo useradd -m newuser → With home directory.
userdel – Delete user.
usermod – Modify user.
passwd – Change password.
groupadd – Create group.
groupdel – Delete group.
groups – Show user groups.
su – Switch user.
sudo – Run as another user (root).
chmod – Change permissions.
chown – Change file owner.
Networking
1. ping – Check connectivity
o Example: ping [Link] → Test if you can reach Google.
2. curl – Send HTTP requests
o Example: curl [Link] → Fetch contents of a webpage.
3. wget – Download files
o Example: wget [Link] → Download a file from the
internet.
4. ssh – Secure shell login
o Example: ssh user@[Link] → Log in to a remote server.
5. scp – Copy files over SSH
o Example: scp [Link] user@[Link]:/home/user/ → Copy file to
remote server.
6. telnet – Remote connect (insecure)
o Example: telnet [Link] → Open a telnet session.
7. nslookup – DNS query
o Example: nslookup [Link] → Show IP of [Link].
8. dig – DNS lookup
o Example: dig [Link] → Query DNS records in detail.
9. iptables – Firewall rules
o Example: sudo iptables -L → List current firewall rules.
10. firewalld – Firewall management (CentOS/RHEL)
Example: sudo firewall-cmd --list-all → Show active firewall rules.
11. hostname – Show or set system hostname
Example: hostname → Display current hostname.
Example: sudo hostname new-host → Set hostname to new-host.
Process Management
ps – List processes
Example: ps aux → Show all running processes with details.
kill <PID> – Kill process by PID
Example: kill 1234 → Kill process with PID 1234.
pkill <name> – Kill processes by name
Example: pkill firefox → Kill all processes named "firefox".
killall <name> – Kill all processes of a program
Example: killall chrome → Kill all Chrome browser processes.
bg – Resume job in background
Example: Run sleep 100, then press Ctrl+Z to pause, then type bg to resume in
background.
fg – Bring job to foreground
Example: Run sleep 100 & to start in background, then type fg to bring it to
foreground.
jobs – List jobs
Example: jobs → Show jobs running in current shell session.
Disk Management
1. fdisk – Partition disk
Example: sudo fdisk -l → List all disk partitions.
2. mkfs – Create a filesystem
Example: sudo mkfs.ext4 /dev/sdb1 → Format /dev/sdb1 with ext4 filesystem.
3. mount – Mount filesystem
Example: sudo mount /dev/sdb1 /mnt → Mount /dev/sdb1 to /mnt.
4. umount – Unmount filesystem
Example: sudo umount /mnt → Unmount the /mnt directory.
5. lsblk – List block devices
Example: lsblk → Show disks, partitions, and mount points.
6. blkid – Show device attributes
Example: sudo blkid → Display UUID and filesystem type of block devices.