Operations 22 min read

Master the Essential Linux Commands: A Complete Cheat Sheet

This guide presents a comprehensive overview of essential Linux commands—including navigation, file manipulation, searching, permission handling, process management, networking, and redirection—explaining their purposes, common options, and practical examples to help users work more efficiently in the terminal.

Java Backend Technology
Java Backend Technology
Java Backend Technology
Master the Essential Linux Commands: A Complete Cheat Sheet

Linux common commands are widely used tools for file management, process control, networking, and system operations. Mastering commands such as cd, pwd, ls, cp, mv, rm, cat, find, chmod, chown, chgrp, grep, paste, sort, comm, tar, jps, kill, killall, top, touch, mkdir, ps, ping, ifconfig, and redirection operators can greatly improve efficiency.

1. cd command

cd : changes the current working directory. Common options:

cd ..        # return to parent directory
cd ../..     # return to grandparent directory
cd ~         # go to home directory
cd -         # return to previous directory

2. pwd command

pwd : displays the full path of the current working directory.

3. ls command

ls : lists files and directories in the specified path.

ls               # list current directory
ls -l            # detailed list
ls -a            # include hidden files
ls -R            # recursive listing
ls [0-9]         # list items containing numbers

4. cp command

cp : copies files or directories.

-a   # copy attributes
-p   # preserve mode, ownership, timestamps
-i   # prompt before overwrite
-r   # copy directories recursively
-u   # copy only when source is newer

5. mv command

mv : moves or renames files or directories.

-f   # force overwrite without prompting
-i   # prompt before overwrite
-u   # overwrite only if source is newer

6. rm command

rm : removes files or directories.

-f   # ignore nonexistent files, never prompt
-i   # interactive, ask before each removal
-r   # recursive removal (directories)
# Example: rm -rf  # forcefully delete recursively

7. cat command

cat : displays file contents.

cat file1               # view file from start
tac file1               # view file in reverse order
cat -n file1            # show line numbers
more file1              # paginate long file
head -n 2 file1         # first two lines
tail -n 2 file1         # last two lines
tail -n +1000 file1    # from line 1000 onward
cat file | head -n 3000 | tail -n +1000   # lines 1000‑2999

8. find command

find : searches for files and directories.

find / -name file1               # search from root
find / -user user1               # files owned by user1
find /usr/bin -type f -atime +100   # not accessed in 100 days
find /usr/bin -type f -mtime -10    # modified within last 10 days
whereis halt                     # locate binary, source, man page
which halt                       # show full path of executable

9. chmod command

chmod : changes file or directory permissions.

chmod ugo+rwx directory1   # give read/write/execute to all
chmod go-rwx directory1    # remove permissions from group and others

10. chown command

chown : changes file or directory ownership.

chown user file1                     # change owner
chown -R user directory1            # recursive ownership change
chown user:group file1              # change owner and group

11. chgrp command

chgrp : changes the group ownership of a file.

chgrp group1 file1

12. grep command

grep : searches for patterns in files.

grep keyword file.txt               # simple search
grep ^Aug /var/log/messages          # lines starting with Aug
grep [0-9] /var/log/messages         # lines containing digits
grep Aug -R /var/log/*               # recursive search
sed 's/string1/string2/g' file      # replace text
sed '/^$/d' file                     # delete empty lines

13. paste command

paste : merges lines of files side by side.

paste file1 file2                     # default tab delimiter
paste -d '+' file1 file2            # use '+' as delimiter

14. sort command

sort : sorts lines of text.

sort file1 file2                     # alphabetical sort
sort -r file1                        # reverse order
sort -n file1                        # numeric sort
sort -u file1                        # unique lines only

15. comm command

comm : compares two sorted files.

comm -1 file1 file2   # lines only in file1
comm -2 file1 file2   # lines only in file2
comm -3 file1 file2   # lines common to both
comm -i file1 file2   # ignore case
comm -u file1 file2   # output all differing lines

16. tar command

tar : archives and optionally compresses files.

Key options:

-c   # create archive
-t   # list archive contents
-x   # extract archive
-j   # use bzip2 compression
-z   # use gzip compression
-v   # verbose output
-f filename   # specify archive file
-C dir   # change to directory before operation

Examples:

# bzip2 format
tar -jcvf archive.tar.bz2 dir/
# gzip format
tar -zcvf archive.tar.gz dir/
# plain tar (no compression)
tar -cvf archive.tar dir/

17. jps command

jps : lists Java processes.

jps -l   # full package name
jps -m   # show main class arguments

18. kill command

kill : sends signals to processes.

kill PID               # default SIGTERM
kill -9 PID            # SIGKILL (force)
kill -HUP PID          # hang up
kill -STOP PID         # stop process

19. killall command

killall : terminates processes by name.

killall process_name

20. top command

top : displays real‑time system resource usage.

21. touch command

touch : creates an empty file or updates timestamps.

touch new_file.txt

22. mkdir command

mkdir : creates new directories.

mkdir new_dir

23. ps command

ps : reports a snapshot of current processes.

ps aux   # show all processes with details

24. ping command

ping : tests network connectivity.

ping 192.168.1.1

25. ifconfig command

ifconfig : displays network interface configuration.

ifconfig

26. Redirection and Pipes

Operators for directing input and output:

> : redirect output to a file (overwrite)

>> : append output to a file

< : use a file as input

| : pipe output of one command to another

ls > file.txt          # write list to file
date >> file.txt       # append date to file
sort < file.txt        # sort contents of file
ls | grep file        # filter ls output

27. cut command

cut : extracts sections from each line of input.

# extract characters 1 and 3
cut -c 1,3 file.txt
# extract fields 2 and 4 using ':' as delimiter
cut -d ':' -f 2,4 file.txt
# complement: keep everything except characters 1 and 3
cut -c 1,3 --complement file.txt

28. Miscellaneous commands

wc -l file

: count lines in a file more file: view file page by page sudo -i: obtain an interactive root shell

Summary

Common options such as -a (all), -f (force), -i (interactive), and -r (recursive) are used across many commands to control their behavior.

shellcommand-linesystem-administration
Java Backend Technology
Written by

Java Backend Technology

Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!

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.