Linux Commands Cheat Sheet
This document provides a detailed list of 100
commonly used Linux commands, including their
options and usage examples.
File and Directory Operations
1. ls - List directory contents.
Options:
-l: Long listing format.
-a: Show hidden files.
-h: Human-readable file sizes.
-R: Recursively list subdirectories.
Example: ls -lh /home
2. cd - Change directory.
Example: cd /var/log
3. pwd - Print working directory.
Example: pwd
4. mkdir - Create a directory.
Options:
-p: Create parent directories as needed.
Example: mkdir -p /home/user/newdir
5. rmdir - Remove an empty directory.
Example: rmdir /home/user/emptydir
6. rm - Remove files or directories.
Options:
-r: Recursively remove directories.
-f: Force removal without confirmation.
Example: rm -rf /home/user/olddir
7. cp - Copy files or directories.
Options:
-r: Recursively copy directories.
-v: Verbose output.
Example: cp -rv /home/user/source /home/user/destination
8. mv - Move or rename files or directories.
Example: mv /home/user/oldname /home/user/newname
9. touch - Create an empty file or update file timestamp.
Example: touch newfile.txt
10. cat - Display file contents.
Example: cat file.txt
11. more - View file contents one screen at a time.
Example: more largefile.txt
12. less - View file contents with backward navigation.
Example: less largefile.txt
13. head - Display the beginning of a file.
Options:
-n: Number of lines to display.
Example: head -n 10 file.txt
14. tail - Display the end of a file.
Options:
-n: Number of lines to display.
-f: Follow file changes in real-time.
Example: tail -f /var/log/syslog
15. ln - Create hard or symbolic links.
Options:
-s: Create a symbolic link.
Example: ln -s /path/to/file /path/to/link
16. find - Search for files and directories.
Options:
-name: Search by name.
-type: Search by type (e.g., f for files, d for directories).
Example: find /home -name "*.txt"
17. locate - Find files by name.
Example: locate myfile.txt
18. chmod - Change file permissions.
Options:
u+x: Add execute permission for the user.
755: Set permissions to rwxr-xr-x.
Example: chmod 755 script.sh
19.chown - Change file ownership.
Options:
user:group: Change owner and group.
Example: chown user:group file.txt
20. chgrp - Change file group ownership.
Example: chgrp groupname file.txt
Text Processing
21. grep - Search text using patterns.
Options:
-i: Case-insensitive search.
-r: Recursively search directories.
Example: grep -i "error" /var/log/syslog
22. awk - Pattern scanning and processing language.
Example: awk '{print $1}' file.txt
23. sed - Stream editor for filtering and
transforming text.
Example: sed 's/old/new/g' file.txt
24. cut - Remove sections from each line of files.
Options:
-d: Delimiter.
-f: Field number.
Example: cut -d: -f1 /etc/passwd
25. tr - Translate or delete characters.
Example: echo "hello" | tr 'a-z' 'A-Z'
26. sort - Sort lines of text files.
Options:
-r: Reverse sort.
-n: Numeric sort.
Example: sort -n file.txt
27. uniq - Report or omit repeated lines.
Options:
-c: Count occurrences.
Example: uniq -c file.txt
28. wc - Print line, word, and byte counts.
Options:
-l: Count lines.
-w: Count words.
Example: wc -l file.txt
29. diff - Compare files line by line.
Example: diff file1.txt file2.txt
30. patch - Apply changes to files.
Example: patch file.txt < patchfile
31. echo - Display a line of text.
Example: echo "Hello, World!"
32. printf - Format and print data.
Example: printf "Name: %s\n" "Alice"
33. tee - Redirect output to multiple files.
Example: echo "Hello" | tee file1.txt file2.txt
34. nl - Number lines of files.
Example: nl file.txt
35. fold - Wrap each input line to fit specified
width.
Example: fold -w 20 file.txt
System Information and Monitoring
36. uname - Print system information.
Options:
-a: Print all information.
Example: uname -a
37. hostname - Show or set the system’s host
name.
Example: hostname
38. uptime - Show how long the system has been
running.
Example: uptime
39. top - Display Linux processes.
Example: top
40. htop - Interactive process viewer (enhanced
top).
Example: htop
41. ps - Display information about running processes.
Options:
-e: Show all processes.
-f: Full-format listing.
Example: ps -ef
42. pstree - Display processes in a tree format.
Example: pstree
43. free - Display memory usage.
Options:
-h: Human-readable output.
Example: free -h
44. df - Report disk space usage.
Options:
-h: Human-readable output.
Example: df -h
45. du - Estimate file space usage.
Options:
-h: Human-readable output.
-s: Summary of total usage.
Example: du -sh /home
46. vmstat - Report virtual memory statistics.
Example: vmstat 1 5
47. iostat - Report CPU and I/O statistics.
Example: iostat
48. lscpu - Display CPU architecture information.
Example: lscpu
49. lsblk - List block devices.
Example: lsblk
50. lsusb - List USB devices.
Example: lsusb
51. lspci - List PCI devices.
Example: lspci
52. dmesg - Print or control the kernel ring buffer.
Example: dmesg | grep "error"
53. journalctl - Query and display systemd logs.
Example: journalctl -xe
Networking
54. ping - Test network connectivity.
Example: ping google.com
55. ifconfig - Configure or display network interfaces.
Example: ifconfig eth0
56. ip - Show or manipulate routing, devices, and tunnels.
Example: ip addr show
57. netstat - Display network connections.
Example: netstat -tuln
58. ss - Investigate sockets.
Example: ss -tuln
59. dig - DNS lookup utility.
Example: dig google.com
60. nslookup - Query Internet name servers.
Example: nslookup google.com
61. host - DNS lookup utility.
Example: host google.com
62. traceroute - Trace the route packets take to a network
host.
Example: traceroute google.com
63. wget - Non-interactive network downloader.
Example: wget https://example.com/file.zip
64. curl - Transfer data from or to a server.
Example: curl -O https://example.com/file.zip
65. scp - Securely copy files between hosts.
Example: scp file.txt user@remote:/path/to/destination
66. rsync - Synchronize files and directories.
Example: rsync -avz /source/ user@remote:/destination/
67. ssh - Secure shell client.
Example: ssh user@remote
68. ftp - File Transfer Protocol client.
Example: ftp ftp.example.com
69. sftp - Secure File Transfer Protocol client.
Example: sftp user@remote
70. nc (netcat) - Arbitrary TCP and UDP
connections and listens.
Example: nc -zv google.com 80
Package Management
71. apt - Package handling utility (Debian/Ubuntu).
Example: apt install vim
72. yum - Package manager (RHEL/CentOS).
Example: yum install httpd
73. dnf - Next-generation package manager
(Fedora/RHEL).
Example: dnf install nginx
74. rpm - RPM package manager.
Example: rpm -ivh package.rpm
75. dpkg - Debian package manager.
Example: dpkg -i package.deb
76. pacman - Package manager (Arch Linux).
Example: pacman -S vim
77. zypper - Package manager (openSUSE).
Example: zypper install vim
78. snap - Manage snap packages.
Example: snap install vscode
79. flatpak - Manage flatpak applications.
Example: flatpak install flathub org.gnome.Gedit
User and Permission Management
80. useradd - Create a new user.
Example: useradd alice
81. userdel - Delete a user.
Example: userdel alice
82. usermod - Modify a user account.
Example: usermod -aG sudo alice
83. passwd - Change user password.
Example: passwd alice
84. groupadd - Create a new group.
Example: groupadd developers
85. groupdel - Delete a group.
Example: groupdel developers
86. groups - Display group membership.
Example: groups alice
87. id - Print user and group information.
Example: id alice
88. su - Switch user.
Example: su - alice
89. sudo - Execute a command as another user.
Example: sudo apt update
90. visudo - Edit the sudoers file.
Example: visudo
Compression and Archiving
91. tar - Archive files.
Options:
-c: Create archive.
-x: Extract archive.
-v: Verbose output.
-f: Specify archive file.
Example: tar -cvf archive.tar /home/user
92. gzip - Compress files.
Example: gzip file.txt
93. gunzip - Decompress files.
Example: gunzip file.txt.gz
94. bzip2 - Compress files with bzip2.
Example: bzip2 file.txt
95. xz - Compress files with xz.
Example: xz file.txt
96. zip - Package and compress files.
Example: zip archive.zip file.txt
97. unzip - Extract compressed files.
Example: unzip archive.zip
Miscellaneous
98. man - Display the manual page for a
command.
Example: man ls
99. alias - Create command shortcuts.
Example: alias ll='ls -la'
100. history - Display command history.
- Example:history