Skip to content
ALB Wiki

Core Utilities

This is an old revision of this page — revision 4 (2026-10-25 15:01:32 UTC). It may differ from the current revision.

The core utilities are the vocabulary — roughly 150 commands (GNU coreutils plus tar, findutils, and friends) that every Linux carries and every real task composes. This chapter is a working reference: not every flag, but the shape of each tool — what it's for, the flags that earn their keep, and the idioms that combine them. Skim it once, keep it forever.

The file trio

cp -r src/ dest/        # recursive; -a = archive (perms+times)
cp -i file dest         # ask before clobbering
mv old new              # rename/move — free within a filesystem
mv -i file dir/         # safe move
rm -r dir/              # recursive delete — NO UNDO
rm -rf dir/             # force — the honest footgun
rm -i file              # ask each time — the habit worth keeping
mkdir -p a/b/c          # -p makes parents
rmdir emptydir          # only empty dirs — rm -r for real

cp -a preserves everything; mv between filesystems silently becomes copy+delete; rm -rf has no recovery — the three truths nobody forgets after learning them the hard way.

ls -la                  # long + hidden — the working form
ls -lhS                 # human sizes, biggest first
ls -lt                  # newest first
ls -li                  # inode numbers
pwd; cd -; cd ~         # where am I; back; home
stat file               # the full inode record
file mystery            # WHAT is this — magic bytes, not extension
du -sh dir              # total size;  du -h --max-depth=1 for the map
du -h | sort -rh | head # where space went
df -h                   # filesystem free space
which cmd; type -a cmd  # where it lives; all resolutions

Find — the real search engine

find . -name '*.c'                    # by name
find . -iname 'readme*'               # case-insensitive
find / -type f -size +100M 2>/dev/null  # space hogs
find . -mtime -7                      # changed this week
find . -perm 777                      # by mode
find . -user alice -group devs        # by owner
find . -empty                         # empty files/dirs
find . -name '*.log' -delete          # act on results — careful!
find . -name '*.tmp' -exec rm {} +    # exec — {} is each path, + batches
find . -print0 | xargs -0 cmd         # the space-safe pipeline

find ... -exec vs | xargs: -exec {} + is the modern safe form; xargs without -0 breaks on spaces — always pair find -print0 | xargs -0 when filenames might be weird.

Archives — tar, plus the compressors

tar -cf archive.tar dir/      # create
tar -xf archive.tar           # extract
tar -tf archive.tar           # list contents
tar -czf a.tar.gz dir/        # gzip
tar -cjf a.tar.bz2 dir/       # bzip2
tar -cJf a.tar.xz dir/        # xz — best ratio
gzip file; gunzip file.gz     # standalone compressors
xz file; xz -d file.xz
zstd -19 file                 # modern fast+strong
zip -r a.zip dir/; unzip a.zip

The flags decompose: c/x/t mode, f file, z/j/J compressor. tar -tf before -xf — always look before you unpack.

dd — the block-level tool

dd if=/dev/sda of=disk.img bs=4M status=progress   # image a disk
dd if=linux.iso of=/dev/sdX bs=4M status=progress && sync  # bootable USB
dd if=/dev/zero of=file bs=1M count=100            # a 100MB file of zeros
dd if=/dev/urandom of=file bs=1M count=10          # random bytes
dd if=/dev/sda of=/dev/sdb bs=64K conv=noerror,sync # rescue a dying disk

if/of are raw devices as easily as files — dd writes boot sectors, wipes disks, images drives. Check of= twice; it overwrites without asking.

Text plumbing — the everyday filters

cat file; cat a b > combined        # concatenate (useless-cat is a meme for a reason)
head -20 file; tail -20 file        # ends
tail -f /var/log/syslog             # follow — the log-watcher
less file                           # the pager — /to-search, q to quit
wc -l file                          # lines/words/bytes
sort file; sort -n; sort -k2        # sort; numeric; by field
sort | uniq -c | sort -nr           # the histogram idiom
cut -d: -f1 /etc/passwd             # field extraction
cut -c1-80 file                     # by column
tr 'a-z' 'A-Z' < file               # translate chars
tr -d '\n' < file                   # delete chars
tee out.log                         # stdout → both screen AND file
xargs -n1 cmd < list                # build argv from stdin

The process watchers

ps aux                              # everything running
ps -ef | grep name                  # find a process
pgrep -l name                       # PIDs by name
top; htop                           # live views
free -h                             # memory
uptime                              # load averages
kill PID; kill -9 PID; killall name # signals
df -h; mount; umount                # filesystem plumbing

The toolkit map — the rest worth knowing

ToolJob
chmod/chown/chgrppermissions/ownership — deep dive in Users and permissions
ln -s / lnsymlinks / hard links
touchcreate/timestamp files
readlink -fresolve a path fully
basename/dirnamepath surgery
realpathcanonicalize
datetimestamps — date -u, date +%s
seqnumber ranges — seq 1 10
yesinfinite stream — yes | cmd
sleeppause — sleep 5
timeout 10 cmdkill after N seconds
watch -n2 cmdrerun + refresh
man cmd · infothe manuals
apropos kwsearch man pages
alias/unaliasshell shortcuts
historythe command log — !n, !!, Ctrl-R
env/printenvthe environment
uname -akernel/arch
hostnamethe machine's name
id, whoami, who, wwho/what
cal, bccalendar, calculator
od, xxd, hexdumpbinary viewing
strings fileprintable strings in binaries
nm, objdump, readelf, lddbinary anatomy

The complete toolkit — the reference table

ToolThe jobThe form that matters
lslist-la -lhS -lt -li -R -d dir/
cpcopy-r -a -i -u --preserve=all
mvmove/rename-i -u -n
rmremove-r -f -i -I -v
mkdirdirs-p -m mode -v
rmdirempty dirs-p
lnlinks-s symlink; bare = hard link
touchcreate/timestamp-d "date" -t YYYYMMDDhhmm
catconcatenate-n -A (show nonprinting) -s
head/tailends-n20 -c100 -f (follow) +5
lesspager+/pat -N -S -R
wccount-l -w -c -L
sortsort-n -r -u -k2 -t: -h -R
uniqdedupe-c -d -u -i (needs sorted input)
cutfields-d: -f1 -c1-10 -f2-
trtranslate'a-z' 'A-Z' -d '\n' -s ' '
pastejoin cols-d, -s serial
joinrelational join-t: -1 n -2 m -a1
commset ops-12 -13 -23 on sorted
splitbreak files-l 1000 -b 1M -n 4
csplitsplit on patterns/pat/ {*}
teefork outputcmd \| tee file -a
xargsargv from stdin-0 -n1 -P4 -I{} -t
findthe searcherthe full grammar — ch 10
locateindexed searchlocate file (updatedb builds db)
which/type/command -vresolutiontype -a all hits
whereislocate binarieswhereis -b ls
statinode record-c %a %U %s formats
filemagic bytes-i mime -b bare
duusage-sh --max-depth=1 -x -ah
dffs space-h -i -T -x tmpfs
tararchivec/x/t + f + z/j/J + v + -C
gzip/bzip2/xz/zstdcompress-d -k -9 -T0
zip/unzipzip-r -l -d
ddblock copyif of bs count status=progress conv=noerror
shredsecure delete-u -n3 -z
syncflush write cacheafter dd to removable
md5sum/sha256sumchecksums-c file.sums -b
base64/base32encode-d -w0
od/xxd/hexdumphex views-c -C -An
stringsprintable text-n4 -t x -a
nm/objdump/readelf/ldd/arbinary anatomynm -C objdump -d readelf -h ldd ar rcs
datethe clock+%s -d "date" -u -R
cal/ncalcalendar-3 -y -j
seqsequences1 10 -w -s, -f %02g
yesinfinite streamyes \| cmd yes n
sleep/usleeppause5 0.5 1m
timeouttime cap30 cmd -k 5 --signal=KILL
watchrefresh-n1 -d -t -c
timemeasure-v -p — the builtin vs /usr/bin/time
env/printenvenvironment-i -u VAR env VAR=x cmd
printenv/set/exportvarsprintenv VAR
unamesystem id-a -r -m -s -n -v
hostnamethe name-f -i -I
id/whoami/who/w/users/lastwhoid -u w last -20 lastlog
man/info/apropos/whatismanualsman 5 passwd -k kw
alias/unalias/history/fcshell memory!! !n !str Ctrl-R
true/false/test/[predicatestest -f [ -d dir ]
expr/bc/dcmathexpr 1 + 2 bc -l echo '2+2' \| bc
printfformatted output'%s\n' %-10s %05d
readinput-r -p "prompt" -s -a arr
getoptsarg parsingwhile getopts "a:b:" o
basename/dirname/realpath/readlinkpath surgeryrealpath -m readlink -f
mktemptemp files-d -u -t --suffix=.x
installcopy+mode-D -m755 -d
truncate/fallocatefile sizing-s 1G -l 1G
iconv/dos2unix/unix2dosencoding/CRLF-f latin1 -t utf8
locale/localectllocale-a locale -k LC_TIME
stty/tput/reset/clearterminalstty -a cols 80 tput cols
script/scriptreplaysession record-a log -c cmd
expect/unbufferautomationpty-driving
cron/at/batch/anacronschedulingat now +5min atq atrm
logger/systemd-catwrite to sysloglogger -t tag msg
dmesg/journalctl/logrotatethe logs-T -l err -b
mount/umount/findmnt/lsblk/blkidstorage plumbing-o opts -R -l --bind
fdisk/gdisk/parted/cfdisk/sfdiskpartition-l print mkpart
mkfs.*/mkswap/swapon/swapofffilesystemsmkfs.ext4 -L swapon -a
fsck.*/e2fsck/tune2fs/debugfs/dumpe2fsfs tools-n -y -b 32768
badblocks/smartctl/hdparmdisk health-a -I -s
ddrescue/testdisk/photorecrescueimage-dying-disks, partition/files recovery
losetup/kpartxloop devices-f --show -a
lsof/fuseropen files-i :80 -u user +D dir
strace/ltrace/perfsyscall tracing-c -e open -f -o log
nm/ldd/objdump/readelfbinary internalsthe .so dependencies
ldconfig/ldd/LD_*the .so registry-p -v LD_LIBRARY_PATH
getent/nsswitchname serviceshosts passwd services
chroot/unshare/nsenter/setprivcontainerschroot dir cmd unshare -n
ip/ss/ping/traceroute/mtr/dig/host/nslookup/nc/socat/curl/wget/rsync/ssh/scp/sftp/tcpdump/ethtool/iftop/nethogs/iptraf/nmap/ncat/openssl s_client/nload/arp/arping/route/netstat/brctl/bridge/tc/iptables/nft/firewall-cmd/hostnamectl/resolvectlnetworkingthe ch-18 toolkit
ssh/ssh-keygen/ssh-agent/ssh-add/ssh-copy-id/scp/sftp/rsync/mosh/autossh/sshfs/expectremote-L/-R/-D/-i/-p/-N/-f rsync -avz -P
tmux/screen/dtach/abduco/byobu/nohup/disown/setsid/atsessionstmux new -s x attach -t
git/svn/cvs/hg/patch/diff/quilt/diff3/wdiff/colordiff/delta/delta/tig/lazygit/gh/glabvcs + diffsgit log --oneline -p --graph
make/cmake/meson/ninja/autoconf/automake/autoreconf/libtool/pkg-config/ccache/distcc/bear/compdb/mold/lldbuilds-j -C --dry-run -B setup ninja -C
gcc/clang/cc/c++/g++/cpp/as/ld/ar/ranlib/strip/addr2line/c++filt/size/elfedit/eu-*/gdb/lldb/valgrind/strace/ltrace/perf/gcov/clang-format/clang-tidy/scan-build/flawfinder/cppcheckcompilers+debug-save-temps -E -S -c -Wall -g -O2 -fsanitize=address
python3/perl/jq/yq/xmlstarlet/csvkit/miller/dasel/jcdata-format toolsjq .x miller --csv dasel -i json
rg/fd/ag/ack/ripgrepthe modern searchersrg pat fd name — faster grep/find
bat/eza/lsd/tree/ncdu/ranger/vifmthe modern viewsbat file eza -la tree ncdu
fzf/zoxide/direnv/starship/atuin/hyperfine/just/task/entr/watchexec/parallel/moreutils/sponge/ts/vipe/vidir/flock/run-one/retrythe power-user layerfzf fuzzy-find, entr re-run-on-change, parallel
procps/psmisc/fuser/killall/pstree/pmap/pwdx/tloadprocess toolkitpstree -p fuser -k /mnt
vmstat/iostat/mpstat/sar/nmon/dstat/glances/btop/htop/atop/iotop/iftop/nethogs/powertop/s-tui/netdatamonitorssar -u 1 glances iotop -o
stress/stress-ng/sysbench/bonnie/fio/ioping/lmbenchbenchmarks + loadfio io benchmarks, stress-ng load
strace/ltrace/perf/bpftrace/bcc/systemtap/ftrace/dwarves/pahole/crash/drgn/kdump/kexectracing + kernel debugperf top bpftrace -e pahole

The long tail is the point — the toolchain's ~150 core commands are chapter-10's vocabulary; the thousands beyond are the ecosystem the package manager reaches.

The composition idioms

The power isn't any tool — it's the pipes:

history | awk '{print $2}' | sort | uniq -c | sort -rn | head   # your top commands
find . -name '*.log' -exec wc -l {} + | sort -n | tail          # biggest logs
cat access.log | cut -d' ' -f1 | sort | uniq -c | sort -rn | head  # top IPs
ps aux --sort=-%mem | head -11                                   # RAM hogs

sort | uniq -c | sort -rn | head — the frequency-histogram idiom — solves a third of all quick analysis questions by itself.

Where utilities go wrong

SymptomCause
xargs broke on a filenameSpaces — -print0 | xargs -0
rm deleted the wrong treeUnquoted var with spaces — rm -rf "$dir"
find found nothing on other mounts-xdev restricting, or the dir is a mount
tar extracted to wrong place-C dir needed, or cd first
dd hungMissing bs= — defaults to 512-byte blocks
command not found but it existswhich shows path — is it in $PATH?
sort ordered "1 10 2"Needed -n for numeric

Exercises

  1. find /usr/bin -name '*zip*' — inventory the compressors.
  2. history | awk '{print $2}' | sort | uniq -c | sort -rn | head — your actual most-used commands.
  3. dd a 10MB file, tar it, xz it, unroll the whole chain.
  4. find . -empty -delete on a scratch tree.
  5. file five mystery files — extension vs magic bytes.

See also

Categories: Handbook · Linux · Linux Handbook · Reference
This page was last edited 2026-10-25 15:01:32 UTC by ALB Team. What links here