Master Essential Linux Commands: Navigate Files, Manage Permissions, and Automate Tasks
This comprehensive guide covers essential Linux command‑line tools for navigating directories, viewing and manipulating files, searching content, handling permissions, processing text, archiving, system shutdown, and process management, providing practical examples and syntax for each command.
1. Files and Directories
1. cd command
Used to change the current directory; the argument is the path to switch to, which can be absolute or relative.
cd /home – enter /home directory
cd .. – go up one level
cd ../.. – go up two levels
cd – go to the user’s home directory
cd ~user1 – go to user1’s home directory
cd - – return to the previous directory
2. pwd command
pwd displays the current working directory.
3. ls command
Lists files and directories.
ls – list files in the directory
ls -l – detailed list
ls -a – include hidden files
ls -R – recursive listing
ls [0-9] – list names containing numbers
4. cp command
Copies files; can copy multiple files to a directory.
-a – preserve attributes
-p – preserve attributes, similar to -a, often used for backup
-i – prompt before overwriting
-r – recursive copy for directories
-u – copy only when source is newer
5. mv command
Moves or renames files and directories.
-f – force overwrite without prompting
-i – prompt before overwriting
-u – overwrite only if source is newer
6. rm command
Removes files or directories.
-f – force, ignore nonexistent files
-i – interactive, prompt before removal
-r – recursive removal, dangerous for directories
2. Viewing File Content
7. cat command
Displays the content of text files; can be combined with more or less. cat file1 – view from the first byte tac file1 – view in reverse order cat -n file1 – show line numbers more file1 – paginate long files head -n 2 file1 – first two lines tail -n 2 file1 – last two lines tail -n +1000 file1 – from line 1000 onward cat filename | head -n 3000 | tail -n +1000 – lines 1000‑3000 cat filename | tail -n +3000 | head -n 1000 – lines 3000‑3999
3. File Search
8. find command
find / -name file1– search from root find / -user user1 – files owned by user1 find /usr/bin -type f -atime +100 – files not accessed in 100 days find /usr/bin -type f -mtime -10 – files modified within 10 days whereis halt – locate binary, source, or man page which halt – show full path of executable
Delete files larger than 50 M:
find /var/mail/ -size +50M -exec rm {} \;4. Permissions
9. chmod command
ls -lh – display permissions
chmod ugo+rwx directory1 – give read, write, execute to user, group, others
chmod go-rwx directory1 – remove all permissions for group and others
10. chown command
chown user1 file1 – change owner
chown -R user1 directory1 – change owner recursively
chown user1:group1 file1 – change owner and group
11. chgrp command
chgrp group1 file1 – change group
5. Text Processing
12. grep command
grep Aug /var/log/messages– find "Aug" 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/stringa1/stringa2/g' example.txt – replace text sed '/^$/d' example.txt – delete empty lines
13. paste command
paste file1 file2– merge files column‑wise paste -d '+' file1 file2 – merge with "+" delimiter
14. sort command
sort file1 file2– sort contents sort file1 file2 | uniq – unique lines sort file1 file2 | uniq -u – lines only in one file sort file1 file2 | uniq -d – duplicate lines
15. comm command
comm -1 file1 file2– exclude file1 lines comm -2 file1 file2 – exclude file2 lines comm -3 file1 file2 – exclude common lines
6. Archiving and Compression
16. tar command
-c – create archive
-t – list archive contents
-x – extract
-j – use bzip2
-z – use gzip
-v – verbose
-f filename – specify file
-C dir – change to directory
tar -jcv -f filename.tar.bz2 … – compress
tar -jtv -f filename.tar.bz2 – list
tar -jxv -f filename.tar.bz2 -C … – extract
bunzip2 file1.bz2 – decompress
bzip2 file1 – compress
gunzip file1.gz – decompress
gzip file1 – compress
gzip -9 file1 – maximum compression
rar a file1.rar test_file – create rar
rar a file1.rar file1 file2 dir1 – compress multiple
rar x file1.rar – extract
zip file1.zip file1 – create zip
unzip file1.zip – extract zip
zip -r file1.zip file1 file2 dir1 – recursive zip
7. System and Shutdown
shutdown -h now – halt
init 0 – halt
telinit 0 – halt
shutdown -h hh:mm – schedule halt
shutdown -c – cancel scheduled halt
shutdown -r now – reboot
reboot – reboot
logout – log out
time – measure command execution time
8. Process Management
17. jps command
Shows Java processes and their IDs.
18. ps command
-A – all processes
-a – all processes not attached to a terminal
-u – processes of a specific user
-x – extended information
-l – long format
ps aux # view all processes
ps ax # view non‑terminal processes
ps -lA # detailed list of all processes
ps axjf # view process tree19. kill command
Sends a signal to a job or PID.
20. killall command
Sends a signal to all processes with a given name.
21. top command
Real‑time system monitor similar to Windows Task Manager.
Graphical method
kill -9 pid – force kill
killall -9 program_name
pkill program_name
Check process ports:
netstat -tunlp|grep PORT_NUMBERSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
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.
