Linux Commands Cheatsheet
Common tools, practical flags, and quick reminders for everyday terminal work.
Navigation and Files
pwdPrint current directory.
lsList files in current directory.
ls -lahList with details, human-readable sizes, and hidden files.
cd <dir>Change directory (
cd - jumps to previous).mkdir -p <dir/path>Create directory (and parents if needed).
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, rm -rf is dangerous).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).nano <file>Simple terminal editor.
vim <file>Powerful modal editor (
:q! to quit without saving, :wq to save & quit).Search and Filters
grep "pattern" <file>Search for lines containing a pattern.
grep -R "pattern" <dir>Recursive search in a directory tree.
grep -Ri "pattern" <dir>Case-insensitive recursive search.
find . -name "*.log"Find files matching a pattern from current directory down.
sortSort lines from stdin (pipe into it).
uniq [-c]Collapse adjacent duplicates (
-c shows counts; usually after sort).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.
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.
kill -9 <pid>Force kill (SIGKILL) a stuck process.
df -hDisk usage by filesystem (human-readable).
du -sh <path>Total size of a directory or file.
Networking and Archives
ping -c 4 <host>Check connectivity to a host (4 packets).
curl -I <url>Fetch only HTTP headers (quick endpoint check).
curl -O <url>Download a file to current directory.
tar -czf archive.tar.gz <dir>Create a compressed archive from a directory.
tar -xzf archive.tar.gzExtract a
.tar.gz archive.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.