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.
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 directory2. 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 numbers4. 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 newer5. mv command
mv : moves or renames files or directories.
-f # force overwrite without prompting
-i # prompt before overwrite
-u # overwrite only if source is newer6. 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 recursively7. 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‑29998. 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 executable9. 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 others10. 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 group11. chgrp command
chgrp : changes the group ownership of a file.
chgrp group1 file112. 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 lines13. paste command
paste : merges lines of files side by side.
paste file1 file2 # default tab delimiter
paste -d '+' file1 file2 # use '+' as delimiter14. 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 only15. 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 lines16. 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 operationExamples:
# 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 arguments18. 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 process19. killall command
killall : terminates processes by name.
killall process_name20. top command
top : displays real‑time system resource usage.
21. touch command
touch : creates an empty file or updates timestamps.
touch new_file.txt22. mkdir command
mkdir : creates new directories.
mkdir new_dir23. ps command
ps : reports a snapshot of current processes.
ps aux # show all processes with details24. ping command
ping : tests network connectivity.
ping 192.168.1.125. ifconfig command
ifconfig : displays network interface configuration.
ifconfig26. 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 output27. 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.txt28. 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.
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!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
