Lesser-Known Linux Commands

A reference of useful but under-used terminal commands, most of which ship with standard Linux distributions. Run man <command> for full documentation.

Files & Directories

CommandWhat it doesExample
statShows detailed file metadata: size, permissions, timestamps, inodestat report.pdf
fileIdentifies a file's actual type regardless of its extensionfile mystery.bin
mktempSafely creates a unique temporary file or directorytmp=$(mktemp -d)
truncateShrinks or extends a file to an exact sizetruncate -s 0 app.log
shredOverwrites a file before deleting so it is hard to recovershred -u secrets.txt
installCopies a file and sets owner, mode, and destination in one stepinstall -m 755 app /usr/local/bin
ln -sCreates a symbolic link pointing at another file or directoryln -s /var/log/app current-log
readlinkResolves where a symlink actually pointsreadlink -f current-log
basename / dirnameExtracts the filename or directory part of a pathbasename /etc/ssh/sshd_config
treePrints a directory hierarchy as an indented treetree -L 2 /etc
duMeasures disk usage per directorydu -sh */ | sort -h
findmntLists mounted filesystems in a readable treefindmnt -t ext4
renameBatch-renames files using a patternrename 's/.jpeg/.jpg/' *.jpeg

Text Processing

CommandWhat it doesExample
tacPrints a file in reverse line order — cat backwardstac access.log | less
revReverses the characters on each lineecho hello | rev
columnAligns delimited text into neat columnscolumn -t -s, data.csv
commCompares two sorted files: lines unique to each, lines sharedcomm -12 old.txt new.txt
joinJoins two sorted files on a common field, like a database joinjoin ids.txt names.txt
pasteMerges files side by side, line by linepaste names.txt emails.txt
cutExtracts columns or character ranges from each linecut -d: -f1 /etc/passwd
trTranslates or deletes characters in a streamtr 'a-z' 'A-Z' < notes.txt
foldWraps long lines at a fixed widthfold -w 80 -s essay.txt
nlNumbers the lines of a filenl -ba script.sh
shufShuffles lines randomly, or picks a random sampleshuf -n 5 wordlist.txt
splitSplits a large file into chunks by lines or sizesplit -l 1000 big.log part_
csplitSplits a file at lines matching a patterncsplit book.txt /^Chapter/ '{*}'
expand / unexpandConverts tabs to spaces, or spaces to tabsexpand -t 4 code.py
lookFinds lines beginning with a string in a sorted file (fast dictionary lookup)look micro /usr/share/dict/words
diff -uShows differences between files in unified patch formatdiff -u old.conf new.conf
stringsExtracts readable text from binary filesstrings program.bin | grep version
iconvConverts text between character encodingsiconv -f latin1 -t utf8 old.txt
wcCounts lines, words, and byteswc -l *.py

Processes & Jobs

CommandWhat it doesExample
watchRe-runs a command at intervals and displays the outputwatch -n 2 df -h
timeoutRuns a command but kills it after a time limittimeout 30s ./flaky.sh
pgrep / pkillFinds or signals processes by name instead of PIDpkill -f "python server.py"
nohupKeeps a command running after you log outnohup ./backup.sh &
disownDetaches a background job from the shell so it survives exitdisown %1
nice / reniceStarts or adjusts a process at lower CPU prioritynice -n 19 ./heavy-job.sh
ioniceSets a process's disk I/O priorityionice -c 3 tar czf backup.tgz /home
pstreeShows running processes as a parent–child treepstree -p
pidofReturns the PID of a named programpidof nginx
lsofLists open files, including which process holds a portlsof -i :8080
fuserShows which processes are using a file, mount, or portfuser -v /mnt/usb
atSchedules a one-off command for later, without cronecho "reboot" | at 03:00
setsidRuns a command in a new session, fully detached from the terminalsetsid ./daemon.sh
timeMeasures how long a command takes to runtime make

System Information

CommandWhat it doesExample
uname -aPrints kernel version and architectureuname -a
lscpuSummarises CPU model, cores, and cachelscpu
lsblkLists disks and partitions as a treelsblk -f
lsusb / lspciLists connected USB and PCI deviceslsusb
freeShows memory and swap usagefree -h
vmstatReports memory, swap, I/O, and CPU activity over timevmstat 1 5
uptimeShows time since boot and load averagesuptime
lastShows history of logins, reboots, and shutdownslast -n 10
wShows who is logged in and what they are runningw
getentQueries system databases (users, groups, hosts) the way the OS doesgetent passwd alice
dmesgPrints kernel messages — useful after plugging in hardwaredmesg --follow
journalctlQueries systemd logs by service, time, or priorityjournalctl -u nginx --since today
hostnamectlShows or sets the hostname plus OS and kernel infohostnamectl
timedatectlShows or sets time, date, and timezonetimedatectl

Networking

CommandWhat it doesExample
ssInspects sockets and listening ports (modern netstat)ss -tulpn
ipShows or configures interfaces, addresses, and routesip addr show
digQueries DNS records in detaildig +short example.com MX
nc (netcat)Reads and writes raw network connections; quick port testsnc -zv host.local 22
curlTransfers data over HTTP and many other protocolscurl -I https://example.com
wget -cDownloads files, resuming interrupted transferswget -c big.iso
tracerouteShows each network hop to a destinationtraceroute example.com
arpShows the table mapping IP addresses to MAC addressesarp -a
rsyncSyncs files locally or remotely, copying only what changedrsync -avz docs/ server:/backup/

Shell Tricks & Pipes

CommandWhat it doesExample
teeWrites output to a file and passes it along the pipe at the same timemake 2>&1 | tee build.log
xargsBuilds and runs commands from piped inputfind . -name "*.tmp" | xargs rm
scriptRecords your whole terminal session to a filescript session.log
pushd / popdKeeps a stack of directories so you can jump backpushd /etc && popd
dirsShows the current directory stackdirs -v
yesRepeats a string forever — auto-confirms promptsyes | apt-get install pkg
seqGenerates sequences of numbersseq 1 2 20
printfFormats output precisely, more predictably than echoprintf "%05d\n" 42
typeTells you whether a command is a binary, alias, or shell builtintype ls
whichShows the full path of the binary that would runwhich python3
aliasDefines shortcuts for longer commandsalias ll='ls -alF'
historyLists past commands; pair with !n to re-run onehistory | grep ssh
fcOpens your last command in an editor to fix and re-run itfc
readReads user input into a variable in scriptsread -p "Name: " name

Miscellaneous

CommandWhat it doesExample
calPrints a calendar in the terminalcal -3
datePrints or formats the current date and timedate +%Y-%m-%d
bcArbitrary-precision calculatorecho "scale=4; 22/7" | bc
factorPrints the prime factorisation of a numberfactor 1234567
unitsConverts between units of measurementunits "60 mph" "km/h"
sleepPauses for a given duration — useful in scripts and loopssleep 5m
md5sum / sha256sumComputes checksums to verify file integritysha256sum download.iso
base64Encodes or decodes data as base64base64 -d secret.b64
xxdProduces a hex dump of a file, or reverses one back to binaryxxd header.bin | head
envLists environment variables, or runs a command with a modified setenv LANG=C sort file.txt
whoami / idShows your username, UID, and group membershipsid
tputControls terminal features like colours and cursor positiontput setaf 2; echo OK

Nearly all of these are part of coreutils, util-linux, procps, or iproute2 and come preinstalled on most Linux distributions.