Fundamentals 35 min read

Master Essential Linux Commands: A Complete Cheat‑Sheet for System Operations

This comprehensive guide lists over 90 essential Linux commands with their most useful options and examples, covering file management, system monitoring, user administration, networking, and scripting to help both beginners and experienced users work efficiently in the terminal.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Essential Linux Commands: A Complete Cheat‑Sheet for System Operations

1. ls

-a  List all files including hidden files that start with a dot.
-A  List all files except "." and "..".
-l  Use long format to display detailed file information.
-c  Sort by ctime.
-t  Sort by modification time.
--color[=WHEN] Colorize output; WHEN can be 'never', 'always', or 'auto'.
Color legend: white – regular file, blue – directory, green – executable, red – compressed, light blue – symbolic link, blinking red – broken link, yellow – device file, gray – other.

2. mv

-b  Make a backup before overwriting.
-f  Force overwrite without prompting.
-i  Prompt before overwriting.
-u  Overwrite only if the source file is newer.
-t  Move multiple source files to a target directory (target first, then sources).
Example: mv a /tmp/   # Move file a to /tmp directory.
Example: mv a b       # Rename file a to b.
Example: mv /home/zenghao test1.txt test2.txt test3.txt

3. cp

-r -R  Recursively copy directories and their contents.
-p  Preserve file attributes.
-f  Force copy without prompting.
-s  Create a symbolic link.
-a  Preserve all file attributes (archive mode).

4. scp

-v  Verbose output.
-r  Recursively copy directories.
Usage examples:
scp local_file user@remote_ip:remote_folder
scp local_file user@remote_ip:remote_file
scp local_file remote_ip:remote_folder
scp local_file remote_ip:remote_file
When username is specified, password is required.
When only remote path is given, password and username are prompted.

5. rm

-r  Remove directories recursively.
-f  Force removal without prompts.
-i  Interactive removal (prompt before each delete).
-v  Verbose output showing each step.

6. touch

-a  Change only the access time.
-m  Change only the modification time.
-r  Example: touch -r a b   # Make b's timestamps match a's.
-t  Specify a custom timestamp (e.g., touch -t 201211142234.50 log.log).

7. pwd

Display the current working directory.

8. cd

-  Return to the previous directory.
.. Return to the parent directory.
<Enter> Return to the home directory.
/  Root directory.

9. mkdir

-p  Create parent directories as needed.
-m  Set custom permissions (e.g., mkdir -m 777 hehe).
-v  Verbose output showing directory creation.

10. rmdir

-v  Verbose output.
-p  Remove parent directories if they become empty.

11. rm (multiple files)

-f  Ignore nonexistent files, no warnings.
-i  Interactive deletion.
-r  Recursively delete directories.
-v  Verbose output.

12. echo

-n  Do not output the trailing newline.
-e  Enable interpretation of backslash escapes.
Example: echo "he
he"   # Prints he
he.
Example: echo -e "he
he"   # Prints he (newline) he.

13. cat

-n  Number all output lines.
-E  Display $ at the end of each line.

14. tac

Display file contents in reverse order.

15. more

+n  Start display at line n.
-n  Show n lines per screen.
+/String  Search for a string and start two lines before the match.
-c  Clear screen before displaying.
-p  Clear screen when paging.

16. less

-m  Show a percentage similar to more.
-N  Show line numbers.
/STRING  Search forward for STRING.
?STRING  Search backward for STRING.
n  Repeat previous search forward.
N  Repeat previous search backward.
b  Scroll back one page.
d  Scroll back half a page.

17. nl

-b  Number all lines, including empty ones (like cat -n).
-b a  Number all lines, even empty ones.
-b t  Do not number empty lines (default).
-n  Various formatting options for line numbers.

18. head

-v  Show file names.
-c number  Show the first number characters; negative number shows all but the last number characters.
-number/n  Show the first number lines; negative number shows all but the last number lines.

19. tail

-v  Verbose output.
-q  Quiet mode (no headers).
-num / -n num  Show the last num lines.
-n +num  Start displaying from line num.
-c  Show the last num characters.
-f  Follow the file (like `tail -f`).

20. vi

:w filename          Save file as filename.
:wq                  Write and quit.
:q!                  Quit without saving.
Insert mode: i, a, o.
Esc returns to command mode.
Cursor movement: h (left), j (down), k (up), l (right).
Page navigation: Ctrl+b (back), Ctrl+f (forward), Ctrl+u (half back), Ctrl+d (half forward).
0  Go to start of file.
G  Go to end of file.
$  End of current line.
^  Start of current line.
w  Jump to next word.
e  Jump to end of word.
b  Jump to previous word.
#l  Move to column # on the current line.
Delete: x (delete char after cursor), X (delete char before cursor), dd (delete line), #dd (delete # lines).
Copy: yw (yank to end of word), yy (yank line), #yy (yank # lines).
Paste: p.
Replace: r (replace single char), R (replace until Esc).
Undo: u.
Change: cw (change word), c#w (change # words).
Go to line: #G (e.g., 15G).

21. which

Locate the executable file of a command in the directories listed in $PATH.

22. whereis

-b  Locate binary.
-m  Locate manual.
-s  Locate source.
-u  Locate other files.
-B  Specify search path for binaries.
-M  Specify search path for manuals.
-S  Specify search path for sources.

23. locate

-r  Use regular expression for searching.

24. find

Time options: -atime, -ctime, -mtime, -amin, -cmin, -mmin.
User/group options: -uid n, -gid n, -user name, -group name, -nouser, -nogroup.
Name/size/type options: -name pattern, -size [+|-]SIZE, -type f/d/l/etc.
Permission options: -perm mode, -perm -mode, -perm +mode.
Actions: -exec command {}, -print (default), -print0, xargs.

25. grep

-c  Print only the count of matching lines.
-I  Case‑insensitive matching (for single‑byte characters).
-l  Print only the names of files with matches.
-v  Invert match (show non‑matching lines).
-n  Show line numbers with matches.

26. file

Determine file type.

27. gzip

-d  Decompress.
-c  Write output to standard output.
-v  Show compression ratio and other info.
-#  Set compression level (1 fastest, 9 best).

28. gunzip

Decompress gzip files.

29. bzip2

-d  Decompress.
-z  Compress.
-k  Keep original file.
-c  Write output to standard output.
-v  Verbose.
-#  Compression level (1 fastest, 9 best).

30. tar

Main options:
-c  Create archive.
-t  List archive contents.
-x  Extract archive.
Auxiliary options:
-j  Filter through bzip2.
-z  Filter through gzip.
-v  Verbose.
-f filename  Specify archive file name.
-C directory  Change to directory before extraction.
--exclude FILE  Exclude FILE from archive.
-p  Preserve permissions.
-P  Preserve absolute paths.
Examples:
 tar -cvf archive.tar files      # Create.
 tar -tvf archive.tar            # List.
 tar -xvf archive.tar            # Extract.
 tar -jcvf archive.tar.bz2 files  # Bzip2 compression.
 tar -zcvf archive.tar.gz files  # Gzip compression.

31. exit

Exit the current shell.

32. logout

Logout from the current login shell.

33. shutdown -h now

Power off the system immediately.

34. users

Display currently logged‑in users.

35. who

-H or --heading  Show column headings.

36. w

-s  Short format (no login time, terminal, CPU time).
-h  Hide column headings.

37. write

Send a message to another logged‑in user.

38. wall

Broadcast a message to all logged‑in users.

39. last

Show login history of users.

40. lastlog

Show the last login time of each user.

41. finger

-s  Show short info (login name, real name, terminal, idle time, login time).
-l  Show long info (including home directory, shell, mail status, .plan, .project, .forward).
-p  Same as -l but omit .plan and .project.

42. hostname

Display or set the system's host name.

43. alias

Define command aliases, e.g., alias ii="ls -l".

44. unalias

Remove a command alias.

45. useradd

-M  Do not create a home directory.
-m  Create a home directory.
-r  Create a system account (UID limited).
-e  Set account expiration date (YYYY‑MM‑DD).
-D  Show default values.
Other options: -u UID, -g initial‑group, -G secondary‑groups, -c comment, -d home‑dir, -s shell.

46. passwd

-l  Lock password.
-u  Unlock password.
-S  Show password file parameters.
-n days  Set minimum days between password changes.
-x days  Set maximum days before password must be changed.
-w days  Set warning period before expiration.
-i date  Set account expiration date.
Use pipe to set password: echo "newpass" | passwd --stdin username.

47. userdel

-r  Remove user's home directory and mail spool.

48. chage

-l  List password aging information.
-d YYYY‑MM‑DD  Set last password change date.
-E YYYY‑MM‑DD  Set account expiration date.
-I days  Set password inactivity period.
-m days  Set minimum password age.
-M days  Set maximum password age.
-W days  Set warning period before expiration.

49. usermod

-c comment  Change GECOS field.
-d dir      Change home directory.
-e YYYY‑MM‑DD  Set account expiration date.
-f days     Set password inactivity period.
-g gid      Change primary group.
-G groups   Set secondary groups.
-l newname  Change login name.
-s shell    Change login shell.
-u UID      Change user ID.
-L          Lock account.
-U          Unlock account.

50. id

Display user and group IDs for a given username.

51. groups

List groups the current user belongs to; the first group is the primary group.

52. newgrp

Log in to a new group.

53. groupadd

-g gid  Specify GID for the new group.

54. groupmod

-g gid  Change GID.
-n name  Change group name.

55. groupdel

Delete a group.

56. gpasswd

Root actions:
 -gpasswd groupname          Set group password.
 -gpasswd -A user1,... -M user2,... groupname  Assign administrators and members.
 -gpasswd -r groupname       Remove group password.
Group member actions:
 -gpasswd -a user groupname   Add user to group.
 -gpasswd -d user groupname   Remove user from group.

57. chfn

Change personal information (GECOS fields) for a user.

58. mount

-ro  Mount read‑only.
-rw  Mount read‑write.
Example: mount /home/mydisk.iso /tmp/mnt

59. umount

Unmount a filesystem.

60. cut

-b  Cut by byte positions.
-c  Cut by character positions.
-d delim  Use DELIM as field delimiter (default TAB).
-f  Select only these fields (used with -d).

61. sort

-n  Sort numerically.
-o file  Write output to FILE.
-r  Reverse sort order.
-t delim  Use DELIM as field separator.
-k  Sort by key (field range).

62. wc

-l  Count lines.
-c  Count bytes.
-m  Count characters.
-w  Count words.

63. uniq

-c  Prefix lines by the number of occurrences.
-d  Only print duplicate lines.
-f N  Skip N fields when comparing.
-s N  Skip N characters when comparing.
-u  Only print unique lines.
-w N  Compare only the first N characters.

64. set

Display all shell variables and functions.

65. env

Display the environment variables.

66. export

Mark a variable for export to the environment of subsequent commands.

67. unset

Remove a variable or function definition.

68. read

-p prompt  Display PROMPT before reading.
-t seconds  Timeout after SECONDS.

69. declare / typeset

-i  Declare integer.
-a  Declare array.
-f  Declare function.
-r  Declare read‑only.

70. ulimit

-f  Set maximum file size (in blocks, usually kilobytes).
Example: ulimit -f 1024  # Limit files to 1 MiB.

71. df

-a  Show all filesystems.
-h  Human‑readable sizes.
-l  Show local filesystems only.
-i  Show inode information.
-T  Show filesystem type.

72. du

-h  Human‑readable output.
-s  Show only a total for each argument.

73. ln

-s  Create a symbolic link.
-v  Verbose output.

74. diff

-b  Ignore changes in the amount of whitespace.
-B  Ignore changes whose lines are all blank.
-i  Ignore case differences.
-q  Report only when files differ.
Example: diff -u file1 file2 > patch.log

75. date

Format specifiers:
%H  Hour (00‑23).
%M  Minute (00‑59).
%P  am/pm.
%D  Date (MM/DD/YY).
%U  Week number of the year.
Set date: date -s "2015-10-17 01:01:01"
Display date: date +%Y%m%d
Relative dates: date -d "2 weeks"

76. cal

-1  Show current month.
-3  Show previous, current, and next month.
-m  Monday as first day of week.
-s  Sunday as first day (default).
-j  Show day of year.
-y  Show the whole year.

77. ps

a   Show all processes.
-a  Show processes for all users on the current terminal.
-e  Show environment.
-f  Show process hierarchy.
-H  Show tree view.
-r  Show processes for the current terminal.
-T  Show all processes for the current terminal.
-aux  Show all processes with detailed info.
-u user  Show processes for a specific user.

78. top

Interactive real‑time view of running processes.

79. kill

Terminate a process by PID.

80. free

Display memory usage (total, used, free, buffers, swap).

81. vmstat

Report virtual memory, processes, CPU activity.

82. iostat

-p [device]  Show statistics for the specified device or partition.

83. watch

-n seconds  Interval between executions.
-d  Highlight differences between updates.

84. at

Schedule a one‑time command.
Time format: HH:MM[am|pm] [+ number unit] (units: minutes|hours|days|weeks).
Commands: atq (list pending jobs), atrm n (remove job n), at -c n (show job n).

85. crontab

file   Load crontab from file.
-e      Edit current user's crontab.
-l      List current user's crontab.
-r      Remove current user's crontab.

86. ifconfig

Configure network interfaces (display, set IP, netmask, etc.).

87. route

Display or modify the IP routing table.

88. ping

-q  Quiet output (summary only).

89. netstat

Show network statistics for IP, TCP, UDP, and ICMP.

90. telnet

Remote login using plain‑text transmission (insecure).

91. rcp

-r  Recursive copy.
-p  Preserve file attributes.
Usage: rcp -r remote_host:remote_dir local_dir

92. wget

-O FILE  Write output to FILE.
--limit-rate=300k  Limit download speed.

93. awk

-F delim  Set input field separator.
{ script }  Action to perform on each line.
Example: cat /etc/passwd | awk -F ':' '{print $1"\t"$7}'

94. sed

a  Append after the current line.
 c  Change lines.
 d  Delete lines.
 i  Insert before the current line.
Example: sed '1,2c Hi' file

95. paste

-d delim  Use DELIM as the output delimiter.
-s  Paste sequentially, one file per line.

96. su

-l  Simulate a full login (change environment, directory).
-c command  Execute COMMAND as the target user and return.

97. sudo

-l  List allowed commands for the invoking user.
-u username  Run command as USERNAME.
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxShellcommand-lineSystem Administration
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.