Essential Linux File Management Commands (Part 2)
This guide walks through essential Linux file‑management commands—cat, more, less, head, tail, du, wc, grep, cut, sort, uniq, which, find, md5sum and tr—showing their common options and practical examples for everyday operations.
cat: view file contents
Displays the entire file and supports several options:
cat -n aa.txt // show line numbers
cat -b aa.txt // show line numbers for non‑empty lines
cat -A aa.txt // show all special characters
cat -E aa.txt // show $ as end‑of‑line markermore: paginate text output
Interactive navigation while viewing:
b / space: page up / down
Enter: line break
q: quitless: advanced pagination
Provides more navigation keys:
Up/Down arrows: scroll line by line
b / space: page up / down
Enter: line break
q: quithead: show file beginning
Shows the first N lines (default 10). Example shows first 15 lines:
head -n 15 /var/log/messagetail: show file end
Shows the last N lines (default 10) and can follow a file in real time:
tail -n 15 /var/log/message // last 15 lines
tail -f /var/log/message // follow updatesdu: disk usage of directories/files
Summarizes size; -s for current directory, -h for human‑readable output:
du -sh /app // total size of /app in readable formatwc: word, line, byte count
Counts lines, words, bytes. Example counts lines in a file:
wc -l /app/aa.txt // line count
-c // byte count
-W // word countgrep: search text patterns
Filters lines matching a pattern, with common flags:
grep -i "physicAl iD" /proc/cpuinfo // case‑insensitive search
grep -i "^$" /proc/cpuinfo // match empty lines
-v // invert match
-i // ignore case
-r // recursive search
-E // extended regex, e.g., -E "a|b|c"cut: extract columns or characters
Extracts fields using a delimiter:
cut -d: -f1 /etc/passwd | head -3 // first field of passwd, first 3 lines
-d // delimiter
-f // field numbers (e.g., -f1,3 or -f1-3)sort: order text lines
Sorts numerically, reverse, by specific columns, with custom delimiters:
sort -nr -k2 sort_demo.txt // numeric reverse sort by column 2
sort -t: -nk3 /etc/passwd // numeric sort by column 3 using ':'
-n // numeric sort
-r // reverse order
-k // key (column)
-t // field delimiteruniq: filter duplicate lines
Counts or removes repeated lines:
uniq -c uniq.txt // prefix each line with occurrence count
-c // count occurrences
-d // show only duplicates
-u // show only unique lines
-i // ignore casewhich: locate executable path
Shows where a command resides in the system:
which cat
which lsfind: locate files and directories
Powerful search with many predicates:
find /etc -name init // exact name match
find / -name "pass" // exact filename
find / -size +204800k // files larger than 200 MB
find / -user root // files owned by root
find /etc -size +102400k -a -size -204800k // size between 100 MB and 200 MB
find /etc -name inittab -exec ls -l {} \; // show details of matching file
find / -size +200M -a -size -300M // size between 200 MB and 300 MB
find / -name "*pass*" // fuzzy match (slower)
find / -type b // block devices
find / -type c // character devicesmd5sum: compute and verify MD5 checksums
Used to detect file changes:
md5sum 111.txt // prints MD5 hash for verificationtr: translate or delete characters
Works with pipelines to transform text streams:
cat test | tr 'A-Z' 'a-z' // convert uppercase to lowercase
cat test | tr -d 'A-Z' // delete all uppercase lettersSigned-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.
Linux Cloud-Native Ops Stack
Focused on practical internet operations, sharing server monitoring, troubleshooting, automated deployment, and cloud-native tech insights. From Linux basics to advanced K8s, from ops tools to architecture optimization, helping engineers avoid pitfalls, grow quickly, and become your tech companion.
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.
