Linux Commands Cheatsheet
Common tools, practical flags, and quick reminders for everyday terminal work.
Navigation and Files
pwdPrint current directory.
ls -lahList with details, human-readable sizes, and hidden files.
treeShow folder tree (may require install).
cd <dir>Change directory (
cd - jumps to previous).mkdir -p <dir/path>Create directory (and parents if needed).
touch <file>Create an empty file or update timestamps.
cp [-r] <src> <dst>Copy files (
-r for directories).mv <src> <dst>Move or rename files/directories.
rm <file>Remove a file (
rm -r for directories; be careful with rm -rf).ln -s <target> <link>Create a symbolic link.
stat <file>View detailed file metadata.
Viewing and Editing
cat <file>Print entire file to stdout.
less <file>View file with paging and search (
/ to search, q to quit).head -n 20 <file>Show first 20 lines.
tail -n 20 <file>Show last 20 lines;
tail -f follows new lines (logs).sed -n '1,20p' <file>Print a range of lines without opening an editor.
nano <file>Simple terminal editor.
vim <file>Powerful modal editor (
:q! to quit without saving, :wq to save and quit).Search and Filters
grep "pattern" <file>Search for lines containing a pattern.
grep -R "pattern" <dir>Recursive search in a directory tree.
rg "pattern"Fast ripgrep search (if installed).
find . -name "*.log"Find files matching a pattern from current directory down.
find . -type f -mtime -1Find files modified in the last 24 hours.
xargs -0Safely pass filenames with spaces (paired with
-print0).Text Processing
sortSort lines from stdin (pipe into it).
uniq -cCollapse adjacent duplicates and count them.
wc -lCount lines in a file or stream.
cut -d ',' -f 1Extract the first CSV column.
awk '{print $1}'Print first column of space-delimited text.
tr -d '\r'Strip carriage returns from Windows files.
Permissions and Ownership
chmod +x <file>Make a file executable.
chmod 644 <file>Set read/write for owner, read-only for group/others (common for files).
chmod 755 <dir>Owner can read/write/execute; others read/execute (common for dirs).
chown <user>[:group] <path>Change owner (and optionally group) of file/dir.
chgrp <group> <path>Change group ownership.
umask 022Set default permissions for new files.
Processes and System
ps auxList all processes.
ps aux | grep <name>Find processes by name.
topInteractive view of processes and resource usage (
q to quit).htopNicer version of
top (may require install).kill <pid>Send TERM signal to a process.
pkill -f <name>Kill processes by name pattern.
free -hMemory usage overview.
df -hDisk usage by filesystem (human-readable).
du -sh <path>Total size of a directory or file.
systemctl status <service>Check a systemd service.
journalctl -u <service> -fFollow logs for a service.
Networking and Archives
ip aShow network interfaces and IPs.
ss -tulpnList listening ports and processes.
ping -c 4 <host>Check connectivity to a host (4 packets).
curl -I <url>Fetch only HTTP headers (quick endpoint check).
curl -L -O <url>Download a file and follow redirects.
ssh <user>@<host>SSH into a remote host using your default key.
scp <file> <user>@<host>:<path>Copy a file to a remote host via SSH.
rsync -avz <src> <dst>Fast file sync with progress and resume.
tar -czf archive.tar.gz <dir>Create a compressed archive from a directory.
tar -xzf archive.tar.gzExtract a
.tar.gz archive.zip -r archive.zip <dir>Create a zip archive.
unzip archive.zipExtract a zip archive.
Shell Productivity
historyView recent commands.
!!Repeat the last command.
!$Reuse the last argument from the previous command.
alias ll='ls -lah'Create a handy shortcut.
export VAR=valueSet an environment variable.
source ~/.bashrcReload your shell config.
which <command>Locate the executable on your PATH.
type <command>Show how a command is resolved (alias, function, binary).