0% found this document useful (0 votes)
18 views18 pages

Linux Commands Cheat Sheet

Uploaded by

Ilyas Baraaouche
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views18 pages

Linux Commands Cheat Sheet

Uploaded by

Ilyas Baraaouche
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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 [Link]

10. cat - Display file contents.

Example: cat [Link]


11. more - View file contents one screen at a time.

Example: more [Link]

12. less - View file contents with backward navigation.

Example: less [Link]

13. head - Display the beginning of a file.

Options:
-n: Number of lines to display.

Example: head -n 10 [Link]

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 [Link]

18. chmod - Change file permissions.

Options:
u+x: Add execute permission for the user.
755: Set permissions to rwxr-xr-x.

Example: chmod 755 [Link]

[Link] - Change file ownership.

Options:
user:group: Change owner and group.

Example: chown user:group [Link]

20. chgrp - Change file group ownership.

Example: chgrp groupname [Link]


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}' [Link]

23. sed - Stream editor for filtering and


transforming text.

Example: sed 's/old/new/g' [Link]

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 [Link]

27. uniq - Report or omit repeated lines.

Options:
-c: Count occurrences.

Example: uniq -c [Link]

28. wc - Print line, word, and byte counts.

Options:
-l: Count lines.
-w: Count words.

Example: wc -l [Link]

29. diff - Compare files line by line.

Example: diff [Link] [Link]

30. patch - Apply changes to files.

Example: patch [Link] < 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 [Link] [Link]

34. nl - Number lines of files.

Example: nl [Link]

35. fold - Wrap each input line to fit specified


width.

Example: fold -w 20 [Link]


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 [Link]

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 [Link]

60. nslookup - Query Internet name servers.

Example: nslookup [Link]

61. host - DNS lookup utility.

Example: host [Link]

62. traceroute - Trace the route packets take to a network


host.
Example: traceroute [Link]
63. wget - Non-interactive network downloader.

Example: wget [Link]

64. curl - Transfer data from or to a server.

Example: curl -O [Link]

65. scp - Securely copy files between hosts.

Example: scp [Link] 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 [Link]

69. sftp - Secure File Transfer Protocol client.


Example: sftp user@remote

70. nc (netcat) - Arbitrary TCP and UDP


connections and listens.
Example: nc -zv [Link] 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 [Link]

75. dpkg - Debian package manager.

Example: dpkg -i [Link]

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 [Link]


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 [Link] /home/user

92. gzip - Compress files.


Example: gzip [Link]

93. gunzip - Decompress files.


Example: gunzip [Link]

94. bzip2 - Compress files with bzip2.


Example: bzip2 [Link]

95. xz - Compress files with xz.


Example: xz [Link]
96. zip - Package and compress files.

Example: zip [Link] [Link]

97. unzip - Extract compressed files.

Example: unzip [Link]

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

You might also like