Operations 21 min read

Master the Linux Command Line: Essential Commands Explained

This comprehensive Linux command cheat sheet covers essential tools such as cd, ls, cp, rm, grep, tar, and many others, providing clear syntax, common options, and practical examples to help users efficiently manage files, processes, permissions, and system operations on Linux.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master the Linux Command Line: Essential Commands Explained

Linux Command Cheat Sheet

Foreword

Linux common commands are tools widely used in the Linux operating system to manage files, directories, processes, network communication, software installation, etc. Mastering these commands improves efficiency.

1. cd command

cd : changes the current working directory to the specified directory. Example: cd /home/user. Common options:

cd ..        # go up one level
cd ../..     # go up two levels
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 directory. If no directory is given, lists the current directory.

ls                # list files
ls -l             # detailed list
ls -a             # include hidden files
ls -R             # recursive list
ls [0-9]          # show names containing numbers

4. cp command

cp : copies files or directories. Example: cp file.txt /home/user.

-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. Example: mv file.txt /home/user.

-f  # force, no prompt
-i  # prompt before overwrite
-u  # update only if source is newer

6. rm command

rm : deletes files or directories.

-f  # ignore nonexistent files, no warnings
-i  # prompt before each removal
-r  # recursive delete (for directories)

7. cat command

cat : displays file contents.

cat file1
tac file1          # reverse order
cat -n file1       # number lines
more file1
head -n 2 file1
tail -n 2 file1
tail -n +1000 file1
cat filename | head -n 3000 | tail -n +1000
cat filename | tail -n +3000 | head -n 1000

8. find command

find : searches for files in a directory hierarchy.

find / -name file1
find / -user user1
find /usr/bin -type f -atime +100
find /usr/bin -type f -mtime -10
whereis halt
which halt

9. chmod command

chmod : changes file or directory permissions.

ls -lh
chmod ugo+rwx directory1
chmod go-rwx directory1

10. chown command

chown : changes file owner.

chown user1 file1
chown -R user1 directory1
chown user1:group1 file1

11. chgrp command

chgrp : changes group ownership of a file.

chgrp group1 file1

12. grep command

grep : searches for patterns in files.

grep keyword file.txt
grep Aug /var/log/messages
grep ^Aug /var/log/messages
grep [0-9] /var/log/messages
grep Aug -R /var/log/*
sed 's/string1/string2/g' example.txt
sed '/^$/d' example.txt

13. paste command

paste : merges lines of files.

paste file1 file2
paste -d '+' file1 file2

14. sort command

sort : sorts lines of text files.

sort file1 file2
sort -r          # reverse
sort -n          # numeric
sort -u          # unique
sort -k 5        # sort by field 5

15. comm command

comm : compares two sorted files.

comm file1 file2
comm -1 file1 file2
comm -2 file1 file2
comm -3 file1 file2
comm -i
comm -u

16. tar command

tar : archives and compresses files.

-c  # create archive
-t  # list contents
-x  # extract
-j  # bzip2
-z  # gzip
-v  # verbose
-f filename
-C dir

16-1 Parameter Introduction

-c  # create
-t  # list
-x  # extract
-j  # bzip2
-z  # gzip
-v  # verbose
-f filename
-C dir

16-2 tar.bz2 format

# compress
tar -jcv -f filename.tar.bz2 source
# list
tar -jtv -f filename.tar.bz2
# extract
tar -jxv -f filename.tar.bz2 -C target_dir

16-3 tar.gz format

# compress
tar -zcvf archive_name.tar.gz filename
# extract
tar -zxvf archive_name.tar.gz -C new_dir

16-4 tar format

# pack
tar -cvf archive_name.tar directory_to_compress
# unpack
tar -xvf archive_name.tar -C dir

16-5 zip format

# compress
zip -r archive_name.zip filename
# extract
unzip archive_name.zip

16-6 Other commands

bunzip2 file1.bz2
bzip2 file1
gunzip file1.gz
gzip file1
gzip -9 file1
rar a file1.rar test_file
rar a file1.rar file1 file2 dir1
rar x file1.rar

17. jps command

jps : lists Java processes.

jps -l
jps -m

18. kill command

kill : sends signals to processes.

kill [signal] PID
# default SIGTERM
SIGKILL, SIGHUP, SIGSTOP

19. killall command

killall : terminates processes by name.

20. System shutdown and reboot

shutdown -h now
init 0
telinit 0
shutdown -h hh:mm &
shutdown -c
shutdown -r now
reboot
logout
time command

21. top command

top : displays real‑time system resource usage.

22. touch command

touch : creates an empty file or updates timestamps.

23. mkdir command

mkdir : creates a new directory.

24. ps command

ps : shows currently running processes.

25. ping command

ping : tests network connectivity.

26. ifconfig command

ifconfig : displays network interface configuration.

27. Redirection operators

> : redirects output to a file. ls > file.txt >> : appends output. date >> file.txt < : redirects input from a file. sort < file.txt | : pipes output of one command to another.

ls | grep file

28. cut command

cut : extracts sections from each line of a file.

cut -c 1,3 file.txt
cut -d ':' -f 2,4 file.txt
cut -c 1,3 --complement file.txt

Summary

-a (all): operate on all items

-f (force): do not ask, proceed directly

-i (interactive): ask before operation

-r (recursive): operate recursively

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.

Shellcommand-lineUnixSystem 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.