Common Linux Commands for File Management, Permissions, and System Operations
This article provides a comprehensive overview of essential Linux commands for navigating directories, viewing and manipulating files, managing permissions, compressing archives, and controlling system processes, offering practical examples and syntax for each operation.
This guide introduces fundamental Linux commands used for file and directory management, content viewing, searching, permission handling, compression, and system control.
1. Directory navigation cd /home – change to /home directory cd .. – go up one level cd ../.. – go up two levels cd – go to the user's home directory cd ~user1 – switch to user1's home directory cd - – return to the previous directory
2. Show current path pwd – display the working directory
3. List files ls – list files in the current directory ls -l – detailed list with permissions, size, etc. ls -a – include hidden files ls -R – recursively list subdirectories ls [0-9] – show entries containing digits
4. Copy files cp -a – preserve attributes cp -p – preserve mode, ownership, timestamps (useful for backup) cp -i – prompt before overwriting cp -r – copy directories recursively cp -u – copy only when source is newer
5. Move or rename files mv -f – force overwrite without prompting mv -i – prompt before overwriting mv -u – overwrite only if the source is newer
6. Delete files or directories rm -f – force delete, ignore nonexistent files rm -i – interactive mode, ask before deleting rm -r – recursively delete directories (dangerous)
7. View file contents cat file1 – display file from the beginning tac file1 – display file in reverse order cat -n file1 – number each line more file1 – paginate long files head -n 2 file1 – show first two lines tail -n 2 file1 – show last two lines tail -n +1000 file1 – start displaying from line 1000 cat filename | head -n 3000 | tail -n +1000 – show lines 1000‑3000 cat filename | tail -n +3000 | head -n 1000 – show lines 3000‑3999
8. Search for files find / -name file1 – search from root for a name find / -user user1 – find 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 last 10 days whereis halt – locate binary, source, or man page which halt – show full path of executable find /var/mail/ -size +50M -exec rm {} \; – delete files larger than 50 MB
9. Permission handling ls -lh – list with human‑readable sizes and permissions chmod ugo+rwx directory1 – grant read/write/execute to user, group, others chmod go-rwx directory1 – remove all permissions for group and others
10. Ownership changes chown user1 file1 – change file owner chown -R user1 directory1 – recursively change owner chown user1:group1 file1 – change owner and group chgrp group1 file1 – change group ownership
11. Text processing grep Aug /var/log/messages – find "Aug" in log file 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 all occurrences sed '/^$/d' example.txt – delete empty lines
12. File merging and sorting paste file1 file2 – merge side by side paste -d '+' file1 file2 – merge with "+" delimiter sort file1 file2 – sort contents sort file1 file2 | uniq – unique lines (union) sort file1 file2 | uniq -u – lines unique to each file sort file1 file2 | uniq -d – common lines (intersection) comm -1 file1 file2 – remove lines from file1 comm -2 file1 file2 – remove lines from file2 comm -3 file1 file2 – remove common lines
13. Archiving and compression tar -c – create archive tar -t – list archive contents tar -x – extract archive (use -C to specify directory) tar -jcv -f filename.tar.bz2 – create bzip2‑compressed archive tar -jtv -f filename.tar.bz2 – list bzip2 archive tar -jxv -f filename.tar.bz2 -C – extract bzip2 archive bunzip2 file1.bz2 – decompress bzip2 file bzip2 file1 – compress with bzip2 gunzip file1.gz – decompress gzip file gzip file1 – compress with gzip gzip -9 file1 – maximum compression rar a file1.rar test_file – create RAR archive rar a file1.rar file1 file2 dir1 – add multiple items rar x file1.rar – extract RAR archive zip file1.zip file1 – create ZIP archive unzip file1.zip – extract ZIP archive zip -r file1.zip file1 file2 dir1 – recursively zip directory
14. System shutdown, reboot, and logout shutdown -h now – power off immediately init 0 – another way to halt telinit 0 – halt via telinit shutdown -h hh:mm & – schedule shutdown shutdown -c – cancel scheduled shutdown shutdown -r now – reboot now reboot – reboot logout – log out of the session time command – measure execution time
15. Process management jps – list Java processes ps aux – show all processes ps ax – show processes not attached to a terminal ps -lA – detailed list of all processes ps axjf – display process tree kill -9 pid – force kill a process killall -9 program_name – force kill by name pkill program_name – kill by name netstat -tunlp | grep port – find process using a port
Source: www.nowcoder.com/discuss/151562
Signed-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.
Selected Java Interview Questions
A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!
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.
