Quick reference for essential Linux commands, organized by category with modern alternatives noted.

Table of Contents#

  1. Overview
  2. File and Directory Operations
  3. Text Processing
  4. System Information and Process Management
  5. User and Permission Management
  6. Networking
  7. Compression and Archiving
  8. Package Management
  9. Disk and Filesystem
  10. Miscellaneous Utilities
  11. Modern Tool Alternatives
  12. Troubleshooting
  13. See Also
  14. Sources

1. Overview#

This cheatsheet covers core Linux commands available on most distributions. Commands marked with [deprecated] have modern replacements listed in the Modern Tool Alternatives section.

2. File and Directory Operations#

CommandDescription
lsList directory contents
cdChange directory
pwdPrint the current working directory
cpCopy files and directories
mvMove or rename files and directories
rmRemove files and directories
mkdirCreate directories
rmdirRemove empty directories
lnCreate hard or symbolic links between files
touchCreate empty files or update file timestamps
fileDetermine file type
findSearch for files and directories by criteria
locateFind files by name using a prebuilt database
realpathResolve the absolute path of a file or directory
basenameStrip directory and suffix from filenames
installCopy files and set their permissions in one step
treeDisplay directory structure as a tree
statDisplay detailed file or filesystem status
renameRename multiple files using pattern matching

3. Text Processing#

CommandDescription
catConcatenate and display file content
lessPager for viewing text files (scrollable)
moreDisplay file contents one screen at a time
headOutput the first part of files
tailOutput the last part of files (-f for live follow)
grepSearch for patterns in files using regular expressions
sedStream editor for filtering and transforming text
awkPattern scanning and processing language
cutRemove sections from lines of files
sortSort lines of text files
trTranslate or delete characters
nlNumber lines of files
fmtReformat paragraph text to a given width
expandConvert tabs to spaces
unexpandConvert spaces to tabs
diffCompare files line by line
wcCount lines, words, and bytes in files
uniqFilter adjacent duplicate lines
teeRead from stdin and write to stdout and files simultaneously
xargsBuild and execute command lines from standard input
columnFormat input into columns
pasteMerge lines of files side by side
shufGenerate random permutations of input lines

4. System Information and Process Management#

CommandDescription
topDisplay system resource usage and running processes
psReport a snapshot of current processes
killSend a signal to a process (e.g., SIGTERM, SIGKILL)
uptimeShow how long the system has been running and load averages
unamePrint system information (kernel, architecture)
hostnameShow or set the system hostname
datePrint or set the system date and time
timeMeasure the execution time of a command
nohupRun a command immune to hangups, output to nohup.out
wShow who is logged on and what they are doing
lsofList open files and the processes using them
systemctlControl the systemd system and service manager
journalctlQuery the systemd journal (logs)
dmesgPrint kernel ring buffer messages
crontabSchedule commands or scripts to run automatically
historyView command history
ttyPrint the terminal device file name
clearClear the terminal screen
rebootReboot the system
shutdownShutdown or restart the system

5. User and Permission Management#

CommandDescription
chmodChange file permissions
chownChange file ownership
chgrpChange group ownership of files and directories
useraddAdd a user to the system
usermodModify a user's account information
passwdChange user password
suSwitch user
sudoExecute a command as another user (typically root)
idPrint user and group information
groupsPrint group memberships for a user
usersPrint the list of currently logged-in users
whoamiPrint the current user

6. Networking#

CommandDescription
ipShow and manipulate routing, devices, policy routing, and tunnels
ssDisplay socket statistics (replaced netstat)
netstat[deprecated] Network connection monitoring, use ss instead
pingSend ICMP ECHO_REQUEST to a network host
curlTransfer data with URL syntax (HTTP, FTP, and more)
wgetDownload files from the web
sshSecure shell remote login
scp[deprecated] Securely copy files between hosts, use rsync or sftp instead
rsyncRemote file and directory synchronization (efficient, delta transfer)
nmapNetwork exploration and security auditing
tcpdumpNetwork packet capture and analysis tool
digDNS lookup utility
nslookupQuery DNS name servers (simpler than dig)
traceroutePrint the route packets take to a network host
ncNetcat, a versatile networking utility for reading/writing TCP/UDP

7. Compression and Archiving#

CommandDescription
tarCreate, list, and extract archive files
gzipCompress files using the gzip algorithm
gunzipDecompress gzip-compressed files
zipPackage and compress files into a ZIP archive
unzipExtract files from a ZIP archive
zstdFast lossless compression (better ratio and speed than gzip)
xzHigh-ratio compression using the LZMA2 algorithm
bzip2Compress files using the Burrows-Wheeler algorithm
arCreate, modify, and extract from archives (used for .deb packages)

8. Package Management#

Debian / Ubuntu (APT)#

CommandDescription
apt updateRefresh the package index from repositories
apt upgradeUpgrade all installed packages to their latest versions
apt install <package>Install a package
apt remove <package>Remove a package (keep config files)
apt purge <package>Remove a package and its configuration files
apt search <term>Search for packages by name or description
apt show <package>Display detailed package information
apt autoremoveRemove automatically installed packages no longer needed
dpkg -i <file>.debInstall a local .deb package
dpkg -lList all installed packages

RHEL / Fedora (DNF)#

CommandDescription
dnf check-updateCheck for available package updates
dnf upgradeUpgrade all installed packages
dnf install <package>Install a package
dnf remove <package>Remove a package
dnf search <term>Search for packages
dnf info <package>Display package information
dnf autoremoveRemove unneeded dependencies
dnf list installedList all installed packages

Arch Linux (Pacman)#

CommandDescription
pacman -SyuSynchronize databases and upgrade all packages
pacman -S <package>Install a package
pacman -R <package>Remove a package
pacman -Rs <package>Remove a package and its unused dependencies
pacman -Ss <term>Search for packages in repositories
pacman -Qi <package>Display installed package information
pacman -Qs <term>Search installed packages
pacman -QdtList orphaned packages (no longer needed as dependencies)

Alpine (APK)#

CommandDescription
apk updateUpdate the package index
apk upgradeUpgrade all installed packages
apk add <package>Install a package
apk del <package>Remove a package
apk search <term>Search for packages
apk info <package>Display package information

9. Disk and Filesystem#

CommandDescription
dfReport filesystem disk space usage
duEstimate file and directory space usage
lsblkList block devices and their mount points
mountMount a filesystem
umountUnmount a mounted filesystem
fdiskPartition table manipulator (MBR)
gdiskGPT partition table manipulator
mkfsCreate a filesystem on a partition (e.g., mkfs.ext4, mkfs.xfs)
blkidDisplay block device attributes (UUID, filesystem type)
fsckFilesystem consistency check and repair
shredOverwrite a file to securely erase its contents
truncateShrink or extend a file to the specified size
mknodCreate a special (device) file
mkfifoCreate a named pipe (FIFO)

10. Miscellaneous Utilities#

CommandDescription
echoPrint a line of text to stdout
printfFormat and print data (more control than echo)
aliasCreate a shortcut alias for a command
whichShow the full path of a command
whereisLocate the binary, source, and manual page for a command
manDisplay the manual page for a command
bcCommand-line calculator
calDisplay a calendar
factorPrint prime factors of a number
base32Encode or decode base32 data
base64Encode or decode base64 data
testEvaluate expressions and return exit status
makeBuild automation tool (reads Makefile)
nanoSimple command-line text editor
vimModal text editor
envPrint or set environment variables for a command
exportSet environment variables for the current shell session

11. Modern Tool Alternatives#

These modern tools offer improved performance, better defaults, and more user-friendly output. They are not installed by default on most distributions but are available in standard repositories.

Classic ToolModern AlternativeKey Improvement
findfdSimpler syntax, respects .gitignore, colorized output
grepripgrep (rg)Much faster, respects .gitignore, smart case, Unicode
catbatSyntax highlighting, line numbers, git integration
lseza (formerly exa)Colorized output, git status, tree view, icons
topbtop / htopInteractive, colorized, mouse support, per-core graphs
dudust / ncduVisual directory size breakdown, faster
dfdufColorized table output, groups by device type
diffdeltaSyntax highlighting, side-by-side view, git integration
netstatssFaster, built-in to iproute2, more detailed socket info
ifconfigipRicher feature set, part of iproute2, actively maintained
mantldr / cheatCommunity-driven practical examples, concise
sedsdSimpler regex syntax (no escaping), string-literal mode
curlxh / httpieHuman-friendly HTTP output, JSON highlighting
psprocsColorized, searchable, tree view, Docker awareness
digdogColorized, supports DoH/DoT, cleaner output

Install examples:

# Arch Linux
pacman -S fd ripgrep bat eza btop dust duf git-delta sd

# Debian/Ubuntu
apt install fd-find ripgrep bat exa

# Fedora
dnf install fd-find ripgrep bat eza

Troubleshooting#

IssueCauseSolution
command not foundThe binary is not installed or not in your $PATHInstall the package (apt install <pkg>, pacman -S <pkg>) or add its directory to $PATH in your shell profile
permission deniedThe current user lacks read, write, or execute permission on the file or directoryCheck permissions with ls -l, then use chmod to fix permissions or run with sudo if root access is needed
broken pipeThe receiving end of a pipe closed before the sender finished writing (e.g., head closes early)This is usually harmless; suppress the error by redirecting stderr (2>/dev/null) or restructuring the pipeline
argument list too longToo many filenames expanded by a glob for a single command invocationUse find ... -exec or xargs to process files in batches instead of expanding the glob directly
no space left on deviceThe filesystem or its inode table is fullCheck usage with df -h (space) and df -i (inodes), then remove unnecessary files, logs, or old package caches
too many open filesThe process exceeded the file descriptor limit set by ulimitIncrease the limit with ulimit -n <value> for the session, or set it permanently in /etc/security/limits.conf

See Also#

Sources#