Quick reference for essential Linux commands, organized by category with modern alternatives noted.
Table of Contents#
- Overview
- File and Directory Operations
- Text Processing
- System Information and Process Management
- User and Permission Management
- Networking
- Compression and Archiving
- Package Management
- Disk and Filesystem
- Miscellaneous Utilities
- Modern Tool Alternatives
- Troubleshooting
- See Also
- 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#
| Command | Description |
|---|
ls | List directory contents |
cd | Change directory |
pwd | Print the current working directory |
cp | Copy files and directories |
mv | Move or rename files and directories |
rm | Remove files and directories |
mkdir | Create directories |
rmdir | Remove empty directories |
ln | Create hard or symbolic links between files |
touch | Create empty files or update file timestamps |
file | Determine file type |
find | Search for files and directories by criteria |
locate | Find files by name using a prebuilt database |
realpath | Resolve the absolute path of a file or directory |
basename | Strip directory and suffix from filenames |
install | Copy files and set their permissions in one step |
tree | Display directory structure as a tree |
stat | Display detailed file or filesystem status |
rename | Rename multiple files using pattern matching |
3. Text Processing#
| Command | Description |
|---|
cat | Concatenate and display file content |
less | Pager for viewing text files (scrollable) |
more | Display file contents one screen at a time |
head | Output the first part of files |
tail | Output the last part of files (-f for live follow) |
grep | Search for patterns in files using regular expressions |
sed | Stream editor for filtering and transforming text |
awk | Pattern scanning and processing language |
cut | Remove sections from lines of files |
sort | Sort lines of text files |
tr | Translate or delete characters |
nl | Number lines of files |
fmt | Reformat paragraph text to a given width |
expand | Convert tabs to spaces |
unexpand | Convert spaces to tabs |
diff | Compare files line by line |
wc | Count lines, words, and bytes in files |
uniq | Filter adjacent duplicate lines |
tee | Read from stdin and write to stdout and files simultaneously |
xargs | Build and execute command lines from standard input |
column | Format input into columns |
paste | Merge lines of files side by side |
shuf | Generate random permutations of input lines |
| Command | Description |
|---|
top | Display system resource usage and running processes |
ps | Report a snapshot of current processes |
kill | Send a signal to a process (e.g., SIGTERM, SIGKILL) |
uptime | Show how long the system has been running and load averages |
uname | Print system information (kernel, architecture) |
hostname | Show or set the system hostname |
date | Print or set the system date and time |
time | Measure the execution time of a command |
nohup | Run a command immune to hangups, output to nohup.out |
w | Show who is logged on and what they are doing |
lsof | List open files and the processes using them |
systemctl | Control the systemd system and service manager |
journalctl | Query the systemd journal (logs) |
dmesg | Print kernel ring buffer messages |
crontab | Schedule commands or scripts to run automatically |
history | View command history |
tty | Print the terminal device file name |
clear | Clear the terminal screen |
reboot | Reboot the system |
shutdown | Shutdown or restart the system |
5. User and Permission Management#
| Command | Description |
|---|
chmod | Change file permissions |
chown | Change file ownership |
chgrp | Change group ownership of files and directories |
useradd | Add a user to the system |
usermod | Modify a user's account information |
passwd | Change user password |
su | Switch user |
sudo | Execute a command as another user (typically root) |
id | Print user and group information |
groups | Print group memberships for a user |
users | Print the list of currently logged-in users |
whoami | Print the current user |
6. Networking#
| Command | Description |
|---|
ip | Show and manipulate routing, devices, policy routing, and tunnels |
ss | Display socket statistics (replaced netstat) |
netstat | [deprecated] Network connection monitoring, use ss instead |
ping | Send ICMP ECHO_REQUEST to a network host |
curl | Transfer data with URL syntax (HTTP, FTP, and more) |
wget | Download files from the web |
ssh | Secure shell remote login |
scp | [deprecated] Securely copy files between hosts, use rsync or sftp instead |
rsync | Remote file and directory synchronization (efficient, delta transfer) |
nmap | Network exploration and security auditing |
tcpdump | Network packet capture and analysis tool |
dig | DNS lookup utility |
nslookup | Query DNS name servers (simpler than dig) |
traceroute | Print the route packets take to a network host |
nc | Netcat, a versatile networking utility for reading/writing TCP/UDP |
7. Compression and Archiving#
| Command | Description |
|---|
tar | Create, list, and extract archive files |
gzip | Compress files using the gzip algorithm |
gunzip | Decompress gzip-compressed files |
zip | Package and compress files into a ZIP archive |
unzip | Extract files from a ZIP archive |
zstd | Fast lossless compression (better ratio and speed than gzip) |
xz | High-ratio compression using the LZMA2 algorithm |
bzip2 | Compress files using the Burrows-Wheeler algorithm |
ar | Create, modify, and extract from archives (used for .deb packages) |
8. Package Management#
Debian / Ubuntu (APT)#
| Command | Description |
|---|
apt update | Refresh the package index from repositories |
apt upgrade | Upgrade 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 autoremove | Remove automatically installed packages no longer needed |
dpkg -i <file>.deb | Install a local .deb package |
dpkg -l | List all installed packages |
RHEL / Fedora (DNF)#
| Command | Description |
|---|
dnf check-update | Check for available package updates |
dnf upgrade | Upgrade 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 autoremove | Remove unneeded dependencies |
dnf list installed | List all installed packages |
Arch Linux (Pacman)#
| Command | Description |
|---|
pacman -Syu | Synchronize 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 -Qdt | List orphaned packages (no longer needed as dependencies) |
Alpine (APK)#
| Command | Description |
|---|
apk update | Update the package index |
apk upgrade | Upgrade 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#
| Command | Description |
|---|
df | Report filesystem disk space usage |
du | Estimate file and directory space usage |
lsblk | List block devices and their mount points |
mount | Mount a filesystem |
umount | Unmount a mounted filesystem |
fdisk | Partition table manipulator (MBR) |
gdisk | GPT partition table manipulator |
mkfs | Create a filesystem on a partition (e.g., mkfs.ext4, mkfs.xfs) |
blkid | Display block device attributes (UUID, filesystem type) |
fsck | Filesystem consistency check and repair |
shred | Overwrite a file to securely erase its contents |
truncate | Shrink or extend a file to the specified size |
mknod | Create a special (device) file |
mkfifo | Create a named pipe (FIFO) |
10. Miscellaneous Utilities#
| Command | Description |
|---|
echo | Print a line of text to stdout |
printf | Format and print data (more control than echo) |
alias | Create a shortcut alias for a command |
which | Show the full path of a command |
whereis | Locate the binary, source, and manual page for a command |
man | Display the manual page for a command |
bc | Command-line calculator |
cal | Display a calendar |
factor | Print prime factors of a number |
base32 | Encode or decode base32 data |
base64 | Encode or decode base64 data |
test | Evaluate expressions and return exit status |
make | Build automation tool (reads Makefile) |
nano | Simple command-line text editor |
vim | Modal text editor |
env | Print or set environment variables for a command |
export | Set environment variables for the current shell session |
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 Tool | Modern Alternative | Key Improvement |
|---|
find | fd | Simpler syntax, respects .gitignore, colorized output |
grep | ripgrep (rg) | Much faster, respects .gitignore, smart case, Unicode |
cat | bat | Syntax highlighting, line numbers, git integration |
ls | eza (formerly exa) | Colorized output, git status, tree view, icons |
top | btop / htop | Interactive, colorized, mouse support, per-core graphs |
du | dust / ncdu | Visual directory size breakdown, faster |
df | duf | Colorized table output, groups by device type |
diff | delta | Syntax highlighting, side-by-side view, git integration |
netstat | ss | Faster, built-in to iproute2, more detailed socket info |
ifconfig | ip | Richer feature set, part of iproute2, actively maintained |
man | tldr / cheat | Community-driven practical examples, concise |
sed | sd | Simpler regex syntax (no escaping), string-literal mode |
curl | xh / httpie | Human-friendly HTTP output, JSON highlighting |
ps | procs | Colorized, searchable, tree view, Docker awareness |
dig | dog | Colorized, 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#
| Issue | Cause | Solution |
|---|
command not found | The binary is not installed or not in your $PATH | Install the package (apt install <pkg>, pacman -S <pkg>) or add its directory to $PATH in your shell profile |
permission denied | The current user lacks read, write, or execute permission on the file or directory | Check permissions with ls -l, then use chmod to fix permissions or run with sudo if root access is needed |
broken pipe | The 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 long | Too many filenames expanded by a glob for a single command invocation | Use find ... -exec or xargs to process files in batches instead of expanding the glob directly |
no space left on device | The filesystem or its inode table is full | Check usage with df -h (space) and df -i (inodes), then remove unnecessary files, logs, or old package caches |
too many open files | The process exceeded the file descriptor limit set by ulimit | Increase the limit with ulimit -n <value> for the session, or set it permanently in /etc/security/limits.conf |
See Also#
Sources#