Operations 34 min read

Essential Linux Commands and Options: A Comprehensive Guide

This article provides a detailed reference of common Linux commands—including ls, mv, cp, scp, rm, touch, cd, mkdir, find, grep, tar, chmod, and many others—explaining each option, flag, and typical usage examples to help system administrators and developers work efficiently in the shell.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Essential Linux Commands and Options: A Comprehensive Guide

1. ls [options] [directory]

-a   List all files, including hidden ones starting with '.'
-A   List all files except '.' and '..'
-l   Use a long listing format
-c   Sort by ctime
-t   Sort by modification time
--color[=WHEN]   Colorize output (WHEN can be 'never', 'always', or 'auto')

2. mv [options] source target

-b   Make a backup before overwriting
-f   Force overwrite without prompting
-i   Prompt before overwriting
-u   Overwrite only if the source is newer
-t   Move multiple sources into a target directory (target first, then sources)

3. cp [options] source target

-r -R   Copy directories recursively
-p   Preserve file attributes
-f   Force copy without prompting
-s   Create a symbolic link instead of copying
-a   Preserve all file attributes (equivalent to -dpR)

4. scp [options] source target

-v   Verbose output
-r   Recursively copy directories
Examples:
scp local_file user@remote_ip:/remote_folder
scp -r local_folder user@remote_ip:/remote_folder

5. rm [options] file

-r   Remove directories recursively
-f   Force removal without prompts
-i   Interactive prompting before removal
-v   Verbose output

6. touch [options] file

-a   Change only the access time
-m   Change only the modification time
-r   Use the timestamps from another file
-t   Specify an explicit timestamp (e.g., 201211142234.50)

7. pwd

Display the current working directory.

8. cd

-   Return to the previous directory
..  Return to the parent directory
~   Return to the home directory
/   Root directory

9. mkdir [options] directory

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

10. rmdir

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

11. rm [options] files…

-f   Ignore nonexistent files, never prompt
-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
Examples:
echo "hello"
echo -e "line1
line2"

13. cat [options] file…

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

14. tac

Display file contents in reverse order.

15. more

+n   Start displaying at line n
-n   Show n lines per screen
+/string   Search forward for string
-c   Clear screen before display
-p   Pause with a clear screen between pages

16. less

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

17. nl [options] file…

-b   Number non-blank lines (default)
-b a Number all lines, including blank ones
-b t Number only non‑blank lines
-n   Control number format (left, right, or zero‑filled)

18. head [options] file…

-v   Show file names
-c   Show the first *number* bytes (negative shows all but last *number* bytes)
-n   Show the first *number* lines (negative shows all but last *number* lines)

19. tail [options] file…

-v   Verbose output
-q   Quiet mode (no headers)
-n   Show the last *number* lines
+N   Start output at line *N*
-c   Show the last *number* bytes
-f   Follow the file as it grows

20. vi

:w filename      Save file as *filename*
:wq              Write and quit
:q!              Quit without saving
Insert mode: i, a, o
Command mode: ESC
Navigation: h j k l, Ctrl+b/f/u/d, G, $, ^
Delete: x, X, dd, #dd
Copy/Yank: yw, yy, #yy
Paste: p
Replace: r, R
Undo: u

21. which

Locate the executable file in the directories listed in $PATH.

22. whereis

-b   Locate binaries
-m   Locate manual pages
-s   Locate source files
-u   Locate other files
-B   Search specific binary path
-M   Search specific manual path
-S   Search specific source path

23. locate

-r   Use regular expressions for searching

24. find [path] [options] [actions]

-atime, -ctime, -mtime, -amin, -cmin, -mmin   Find files based on time criteria
-uid n   Find files owned by user ID n
-gid n   Find files owned by group ID n
-name pattern   Match file name pattern
-size [+|-]SIZE   Find files larger or smaller than SIZE (c, k, M, G)
-type f|d|l|b|c|p|s   Filter by file type
-perm mode   Exact permission match
-perm -mode   At least the given permissions
-perm +mode   Any of the given permissions
-exec command {} \;   Execute *command* on each matched file

25. grep ‘pattern’ file

-c   Print only a count of matching lines
-i   Case‑insensitive matching
-l   Print only the names of matching files
-v   Invert match (show non‑matching lines)
-n   Prefix each line with its line number

25. file

Determine file type.

26. gzip [-cdtv#] file

-d   Decompress
-c   Write output to stdout
-v   Verbose (show compression ratio)
-#   Set compression level (1‑fastest, 9‑best)

27. gunzip

Decompress .gz files.

28. bzip2

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

29. bzcat

Read bzip2‑compressed files without decompressing to disk.

30. tar [options] archive [files]

-c   Create archive
-t   List archive contents
-x   Extract archive
-j   Filter through bzip2
-z   Filter through gzip
-v   Verbose
-f   Specify archive file name
-C   Change to directory before operation
--exclude FILE   Exclude FILE from archive
-p   Preserve permissions
-P   Preserve absolute paths

31. exit

Exit the current shell.

32. logout

Log out of a login shell.

33. shutdown -h now

Power off the system immediately.

34. users

Show currently logged‑in users.

35. who

-H   Show column headings

36. w

-s   Short format (no login time, terminal, CPU usage)
-h   Hide 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.

40. lastlog

Show the most recent login of each user.

41. finger [options] [user]

-s   Show short info (login name, real name, terminal, idle time, login time)
-l   Show long info (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 ii="ls -l"

Create an alias.

44. unalias ii

Remove an alias.

45. useradd [options] username

-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 for useradd

46. passwd

-l   Lock the password
-u   Unlock the password
-S   Show password file entry
-n days   Set minimum days between password changes
-x days   Set maximum days before password must be changed
-w days   Set warning days before expiration
-i date   Set account expiration date

47. userdel

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

48. chage [options] username

-l   List password aging information
-d date   Set last password change date (YYYY‑MM‑DD)
-E date   Set account expiration date (YYYY‑MM‑DD)
-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 [options] username

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

50. id [username]

Display user and group IDs.

51. groups

Show groups the current user belongs to.

52. newgrp

Change the current group ID.

53. groupadd [-g gid] groupname

-g gid   Specify GID for the new group

54. groupmod [-g gid] [-n newname] groupname

-g gid   Change GID
-n name  Change group name

55. groupdel groupname

Delete a group.

56. gpasswd

Root actions:
  gpasswd -A user1,... group   Set group administrators
  gpasswd -M user1,... group   Add members to group
  gpasswd -r group             Remove group password
User actions:
  gpasswd -a user group        Add user to group
  gpasswd -d user group        Remove user from group

57. chfn

Change user personal information.

58. mount [-t type] [-o options] device dir

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

59. umount

Unmount a filesystem.

60. cut

-b   Select bytes
-c   Select characters
-d delim   Specify delimiter (default tab)
-f   Select fields

61. sort

-n   Sort numerically
-o file   Write output to *file*
-r   Reverse sort order
-t delim   Use *delim* as field separator
-k n,m   Sort by key from field n to m

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 shell variables and functions.

65. env

Display environment variables.

66. export

Mark a variable for export to the environment.

67. unset

Remove a variable or function.

68. read

-p prompt   Display *prompt* before reading
-t seconds   Timeout after *seconds*

69. declare / typeset

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

70. ulimit

-f   Set maximum file size (in blocks)
Example: ulimit -f 1024   # limit files to 1 MiB

71. df [options] [file]

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

72. du [options] [file]

-h   Human‑readable output
-s   Show only total size

73. ln [options] source target

-s   Create symbolic link
-v   Verbose output

74. diff [options] file1 file2

-b   Ignore changes in the amount of whitespace
-B   Ignore blank lines
-i   Ignore case differences
-q   Report only when files differ

75. date [options] [+format]

%H   Hour (00‑23)
%M   Minute (00‑59)
%P   am/pm
%D   Date (YYYY‑MM‑DD)
%U   Week number of the year
Set date: date -s "2015-10-17 01:01:01"
Show date: date +%Y%m%d

76. cal [options] [month] [year]

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

77. ps [options]

a   Show all processes
-u   Show processes for a specific user
-x   Show processes without a controlling terminal
-H   Show process hierarchy tree
-f   Full‑format listing

78. top [options]

Interactive display of running processes with CPU and memory usage.

79. kill [options] pid

Send signals to terminate processes.

80. free [options]

Display total, used, and free memory and swap.

81. vmstat

Report virtual memory, processes, and CPU activity.

82. iostat [options] [interval] [count]

-p [device]   Show statistics for the specified device(s)

83. watch [options] command

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

84. at [time] command

Schedule a one‑time command.
Examples:
  at 14:30   # run at 2:30 PM today
  at now + 1 hour   # run in one hour
Use atq to list pending jobs, atrm to remove.

85. crontab

-e   Edit current user's crontab
-l   List current user's crontab
-r   Remove current user's crontab

86. ifconfig [interface] [options]

Display or configure network interfaces.

87. route

Display or modify the IP routing table.

88. ping [options] host

-q   Quiet output, only summary

89. netstat

Show network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.

90. telnet [options] host

Remote login using plain‑text protocol (insecure).

91. rcp [options] source target

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

92. wget [options] URL

-O FILE   Write output to *FILE*
--limit-rate=300k   Limit download speed to 300 KB/s

93. awk

-F delim   Set field separator
{ script }   Execute *script* on each line
Example: awk -F ':' '{print $1,$7}' /etc/passwd

94. sed

a   Append text after a line
c   Change (replace) selected lines
d   Delete lines
i   Insert text before a line

95. paste

-d delim   Use *delim* as field delimiter (default tab)
-s   Paste one file per line

96. su [options] [user]

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

97. sudo

-l   List allowed (and forbidden) commands for the invoking user
-u username   Run command as *username*

More Linux articles can be found by clicking "Read Original".

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.

OperationsLinuxShellcommand-line
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.