Linux Command Line
Essential Linux shell commands for file operations, navigation, permissions, processes, and text processing.
The Linux command line is the most powerful interface for development and operations work. This cheatsheet covers navigation, file operations, permissions, process management, and text processing with pipes.
Commands are written for bash/zsh and should work on any Unix-like system including macOS and WSL.
Navigation & File Info
pwdls -lacd <dir>cd ~cd -tree -L 2du -sh <dir>File Operations
cp <src> <dest>mv <src> <dest>rm <file>mkdir -p <path>touch <file>ln -s <target> <link>Permissions & Ownership
chmod 755 <file>chown <user>:<group> <file>Process Management
ps auxtopkill <PID>kill -9 <PID>nohup <cmd> &Text Processing & Pipes
cat <file>less <file>head -n 20 <file>tail -n 20 -f <file>grep -r "pattern" <dir>grep -v "exclude" <file>sed -i "s/old/new/g" <file>awk '{print $1}' <file>sort <file> | uniq -cwc -l <file>Archives & Disk
tar -czvf archive.tar.gz <dir>tar -xzvf archive.tar.gzzip -r archive.zip <dir>df -hfree -hLinux Command Line
Essential Linux shell commands for file operations, navigation, permissions, processes, and text processing.
The Linux command line is the most powerful interface for development and operations work. This cheatsheet covers navigation, file operations, permissions, process management, and text processing with pipes.
Commands are written for bash/zsh and should work on any Unix-like system including macOS and WSL.
Navigation & File Info
pwd — Print the current working directory path.ls -la — List all files and directories with details — permissions, size, owner, modified time.cd <dir> — Change to the specified directory.cd ~ — Change to the home directory.cd - — Change to the previous directory (back and forth toggle).tree -L 2 — Display directory structure as a tree, 2 levels deep.du -sh <dir> — Show total disk usage of a directory in human-readable format.File Operations
cp <src> <dest> — Copy a file or directory (use -r for directories).mv <src> <dest> — Move or rename a file or directory.rm <file> — Delete a file permanently. Use -r for directories, -f to force.mkdir -p <path> — Create a directory, including any necessary parent directories.touch <file> — Create an empty file or update the timestamp of an existing file.ln -s <target> <link> — Create a symbolic (soft) link pointing to a file or directory.Permissions & Ownership
chmod 755 <file> — Set file permissions — owner: rwx, group: rx, others: rx.chown <user>:<group> <file> — Change the owner and group of a file or directory.Process Management
ps aux — List all running processes with detailed info (user, PID, CPU, memory).top — Interactive real-time view of running processes and system resource usage.kill <PID> — Send SIGTERM to a process by PID, asking it to terminate gracefully.kill -9 <PID> — Force kill a process with SIGKILL. Use only if SIGTERM fails.nohup <cmd> & — Run a command immune to hangups, in the background.Text Processing & Pipes
cat <file> — Output the full contents of a file to stdout.less <file> — View file contents with interactive scrolling and search (/ to search).head -n 20 <file> — Print the first 20 lines of a file.tail -n 20 -f <file> — Print the last 20 lines and follow new output as it grows.grep -r "pattern" <dir> — Recursively search for a pattern in files within a directory.grep -v "exclude" <file> — Invert the match — show lines that do NOT contain the pattern.sed -i "s/old/new/g" <file> — Replace all occurrences of old with new in-place using regex.awk '{print $1}' <file> — Print the first column of each line (space-delimited by default).sort <file> | uniq -c — Sort lines and then count unique occurrences.wc -l <file> — Count lines, words, and characters in a file.Archives & Disk
tar -czvf archive.tar.gz <dir> — Create a compressed tarball archive.tar -xzvf archive.tar.gz — Extract a compressed tarball archive.zip -r archive.zip <dir> — Create a compressed zip archive.df -h — Show disk space usage for all mounted filesystems in human-readable format.free -h — Display system memory usage (RAM + swap) in human-readable format.