On this page 10 sections
cut — extract fields
cut extracts specific character positions or delimiter-separated fields. It is ideal for simple structured data where the delimiter is predictable.
cut -d: -f1 /etc/passwdcut -d: -f1,7 /etc/passwdsort — order data
sort orders lines alphabetically by default. -n uses numeric ordering, -r reverses the result and -u removes duplicates while sorting.
sort names.txtsort -nr numbers.txtsort -u hosts.txtuniq — identify duplicates
uniq compares adjacent lines, so input should normally be sorted first. -c counts occurrences and -d prints only duplicated values.
sort hosts.txt | uniq -csort hosts.txt | uniq -dCount frequency
sort and uniq are frequently combined to determine which value appears most often.
sort hosts.txt | uniq -c | sort -nr | headawk '{print $1}' access.log | sort | uniq -c | sort -nr | head -20tr — translate characters
tr replaces or deletes individual characters from a stream. It is useful for case conversion, delimiter conversion and whitespace cleanup.
echo 'sam0x' | tr '[:lower:]' '[:upper:]'tr ',' '\n' < values.csvtr -d '\r' < windows.txt > linux.txtwc — count content
wc counts lines, words and bytes. -l is especially useful for counting results returned by other commands.
wc -l hosts.txtfind /var/www -type f -name "*.php" | wc -lhead and tail
head reads the beginning of input while tail reads the end. They are useful for quickly inspecting large files and limiting pipeline output.
head -n 20 application.logtail -n 50 application.logFollow logs in real time
tail -f keeps the file open and prints new lines as they are appended. This is useful when troubleshooting services while reproducing an issue.
tail -f /var/log/nginx/access.logtail -f /var/log/nginx/error.log | grep -i "error"tee — display and save simultaneously
tee copies standard input to both the terminal and one or more files. -a appends instead of overwriting.
find /opt -type f | tee files.txtecho "api.sam0x.me" | tee -a hosts.txtCombine tools instead of doing everything with one command
Unix tools are designed to compose. A pipeline should normally perform one transformation per stage: select data, extract fields, normalise it, count it and finally limit or save the output.
awk '{print $1}' access.log | sort | uniq -c | sort -nr | headcut -d: -f7 /etc/passwd | sort -ufind /var/www -type f -name "*.php" -exec grep -Hin "password" {} + 2>/dev/null