Linux Command Line
Every essential Linux CLI command: navigation, files, permissions, processes, text processing, archives, and disk, with syntax and real use cases.150 commands · 8 sections
The Linux command line is the developer's home base. This cheatsheet covers the commands you use daily: navigating and inspecting files, creating and moving files, permissions and ownership, managing processes, text processing with grep/sed/awk, archives, and disk usage.
Every command shows its real syntax followed by the use case: when and why you reach for it.
Navigation & File Info20
pwdlsls -lals -lhls -ltls -Rcd <dir>cd ..cd -cd ~find . -name "*.ts"find . -type d -name "node_modules"find . -mtime -7find . -size +100Mfind . -name "*.log" -deletetree -L 2file <file>stat <file>which <cmd>type <cmd>File Operations22
touch <file>mkdir <dir>mkdir -p a/b/ccp <src> <dst>cp -r <src> <dst>cp -a <src> <dst>mv <src> <dst>rm <file>rm -r <dir>rm -rf <dir>rm -i <file>ln -s <target> <link>cat <file>cat file1 file2 > mergedless <file>head -20 <file>tail -20 <file>tail -f <file>wc -l <file>wc -w <file>diff file1 file2diff -r dir1 dir2Permissions & Ownership9
chmod 755 <file>chmod +x <file>chmod 600 <file>chmod -R 755 <dir>chown user:group <file>chown -R user:group <dir>umask 022getfacl <file>setfacl -m u:deploy:rwx <dir>Process Management22
ps auxps aux | grep nodetophtopkill <pid>kill -9 <pid>killall <name>pkill -f <pattern>pgrep -a <name>jobsfgbgcommand &nohup <cmd> &nice -n 10 <cmd>renice 5 -p <pid>crontab -ecrontab -lsystemctl status <service>systemctl start/stop/restart <service>systemctl enable --now <service>journalctl -u <service> -fText Processing & Pipes27
grep "error" app.loggrep -i "error" app.loggrep -r "apiKey" src/grep -l "error" *.loggrep -c "error" app.loggrep -v "debug" app.loggrep -E "error|fatal" app.loggrep -n "error" app.loggrep -r --include="*.js" "TODO" src/sed -i 's/old/new/g' <file>sed -n '1,20p' <file>sed -i '/^#/d' <file>awk '{print $1}' <file>awk -F, '{print $2}' data.csvawk '{sum += $1} END {print sum}' nums.txtcut -d, -f1-3 data.csvcut -c1-10 <file>sort <file>sort -n <file>sort -r <file>sort -u <file>uniq -c <file>wc -l access.log | awk '{print $1}'cat *.log | grep -E "ERROR" | wc -ltee <file>xargs -n1 <cmd>tr '[:lower:]' '[:upper:]' < <file>Archives & Disk17
tar -czf archive.tar.gz <dir>tar -xzf archive.tar.gztar -tzf archive.tar.gztar -xzf archive.tar.gz -C <dir>tar -czf - <dir> | ssh server "tar -xzf - -C /target"zip -r archive.zip <dir>unzip archive.zipunzip -l archive.zipgzip <file>gunzip <file>.gzdf -hdu -sh <dir>du -sh * | sort -rh | head -10du -sh --max-depth=1 . | sort -rhfsck /dev/sda1mount /dev/sdb1 /mnt/dataumount /mnt/dataUsers & Network20
whoamiidsudo -isudo -u <user> <cmd>useradd -m -s /bin/bash <name>passwd <name>usermod -aG sudo <name>userdel -r <name>groupsip addrip routeping <host>curl -I https://www.www.devvkit.comcurl -s https://api.github.com/repos/nodejs/node | jq .stargazers_countwget -O file.zip https://example.com/file.zipss -tulpnnc -zv <host> <port>ssh <user>@<host>scp <file> <user>@<host>:<path>rsync -avz <src> <user>@<host>:<dst>System & Shell13
uname -acat /etc/os-releaseuptimefree -hhistory!!!<n>alias ll='ls -la'export VAR=valueecho $PATHenvshutdown -h nowrebootLinux Command Line
Every essential Linux CLI command: navigation, files, permissions, processes, text processing, archives, and disk, with syntax and real use cases.
The Linux command line is the developer's home base. This cheatsheet covers the commands you use daily: navigating and inspecting files, creating and moving files, permissions and ownership, managing processes, text processing with grep/sed/awk, archives, and disk usage.
Every command shows its real syntax followed by the use case: when and why you reach for it.
Navigation & File Info
pwd: Print the current working directory: where am I?ls: List files in the current directory.ls -la: List ALL files with details: hidden files, permissions, sizes, dates.ls -lh: List files with human-readable sizes (KB, MB, GB).ls -lt: Sort by modification time, newest first: what did I just touch?ls -R: List recursively: see the whole tree.cd <dir>: Change directory.cd ..: Go up one level.cd -: Go to the previous directory: toggle between two folders.cd ~: Go to your home directory.find . -name "*.ts": Find files by name pattern: recursive search.find . -type d -name "node_modules": Find directories by name: locate all node_modules.find . -mtime -7: Files modified in the last 7 days: what changed this week?find . -size +100M: Files larger than 100MB: disk hogs.find . -name "*.log" -delete: Find and delete in one shot: clean up log files.tree -L 2: Show the directory tree 2 levels deep (install with apt install tree).file <file>: Identify a file's type: what is this mystery file?stat <file>: Full metadata: permissions, timestamps, size, inode.which <cmd>: Where is this command installed?type <cmd>: Is it a binary, alias, or shell builtin?File Operations
touch <file>: Create an empty file or update its timestamp.mkdir <dir>: Create a directory.mkdir -p a/b/c: Create nested directories: no error if they exist.cp <src> <dst>: Copy a file.cp -r <src> <dst>: Copy a directory recursively.cp -a <src> <dst>: Copy preserving permissions, ownership, and timestamps: full fidelity.mv <src> <dst>: Move or rename a file.rm <file>: Delete a file. No trash, no undo.rm -r <dir>: Delete a directory and everything inside it.rm -rf <dir>: Force recursive delete: the nuclear option. Double-check the path.rm -i <file>: Interactive delete: confirm each file.ln -s <target> <link>: Create a symlink: point to a file or dir from elsewhere.cat <file>: Print a file's contents.cat file1 file2 > merged: Concatenate files into one.less <file>: View a file page by page: q to quit, / to search.head -20 <file>: First 20 lines: peek at a log or config.tail -20 <file>: Last 20 lines: see the newest entries.tail -f <file>: Follow a file as it grows: live log viewing.wc -l <file>: Count lines: how big is this file?wc -w <file>: Count words.diff file1 file2: Compare two files line by line.diff -r dir1 dir2: Compare two directories recursively.Permissions & Ownership
chmod 755 <file>: Owner rwx, group and others r-x: standard for executables and directories.chmod +x <file>: Make a script executable.chmod 600 <file>: Owner read/write only: private files like SSH keys and .env.chmod -R 755 <dir>: Apply recursively to a directory tree.chown user:group <file>: Change file owner and group.chown -R user:group <dir>: Change ownership recursively: fix permission messes.umask 022: Set default permissions for new files: 022 = 644 for files, 755 for dirs.getfacl <file>: Show extended ACLs: finer-grained permissions.setfacl -m u:deploy:rwx <dir>: Grant a user specific rights via ACL: no chown needed.Process Management
ps aux: List ALL processes with CPU/memory: find what is eating the machine.ps aux | grep node: Filter processes by name: all node processes.top: Live process monitor: refresh every second.htop: Nicer interactive process monitor with tree view.kill <pid>: Send SIGTERM: ask the process to stop gracefully.kill -9 <pid>: Send SIGKILL: force kill. Last resort, skips cleanup.killall <name>: Kill every process with that name.pkill -f <pattern>: Kill processes matching a full command-line pattern.pgrep -a <name>: Find process IDs with their command lines.jobs: List background jobs in the current shell.fg: Bring the most recent background job to the foreground.bg: Resume a stopped job in the background.command &: Run a command in the background: get your prompt back.nohup <cmd> &: Run a command immune to hangup: keep it alive after logout.nice -n 10 <cmd>: Lower a process's priority: run heavy jobs politely.renice 5 -p <pid>: Change priority of a running process.crontab -e: Edit your cron jobs: schedule recurring tasks.crontab -l: List your scheduled jobs.systemctl status <service>: Check a systemd service's status: is nginx running?systemctl start/stop/restart <service>: Manage a service: systemctl restart nginx.systemctl enable --now <service>: Start a service and enable it on boot.journalctl -u <service> -f: Follow a service's logs: systemd logging.Text Processing & Pipes
grep "error" app.log: Find lines containing "error".grep -i "error" app.log: Case-insensitive search.grep -r "apiKey" src/: Recursive search across a directory.grep -l "error" *.log: List filenames only: which logs contain errors?grep -c "error" app.log: Count matching lines.grep -v "debug" app.log: Invert: lines WITHOUT "debug".grep -E "error|fatal" app.log: Extended regex: match multiple patterns.grep -n "error" app.log: Show line numbers: jump straight to the problem.grep -r --include="*.js" "TODO" src/: Search only certain file types.sed -i 's/old/new/g' <file>: Replace all occurrences in place: edit files from the terminal.sed -n '1,20p' <file>: Print lines 1-20: a precise slice.sed -i '/^#/d' <file>: Delete comment lines in place.awk '{print $1}' <file>: Print the first column of each line.awk -F, '{print $2}' data.csv: Split by comma and print column 2: CSV work.awk '{sum += $1} END {print sum}' nums.txt: Sum a column of numbers.cut -d, -f1-3 data.csv: Extract fields 1-3 by delimiter.cut -c1-10 <file>: Extract the first 10 characters of each line.sort <file>: Sort lines alphabetically.sort -n <file>: Sort numerically: sizes, counts, scores.sort -r <file>: Sort in reverse: biggest first.sort -u <file>: Sort and remove duplicates.uniq -c <file>: Count consecutive duplicates: pair with sort first.wc -l access.log | awk '{print $1}': Count lines and strip the filename: script-friendly.cat *.log | grep -E "ERROR" | wc -l: Count errors across all logs: the pipeline pattern.tee <file>: Write output to a file AND keep printing it: capture while watching.xargs -n1 <cmd>: Run a command for each input line: batch operations.tr '[:lower:]' '[:upper:]' < <file>: Translate characters: uppercase conversion.Archives & Disk
tar -czf archive.tar.gz <dir>: Create a compressed archive.tar -xzf archive.tar.gz: Extract a .tar.gz archive.tar -tzf archive.tar.gz: List contents without extracting.tar -xzf archive.tar.gz -C <dir>: Extract into a specific directory.tar -czf - <dir> | ssh server "tar -xzf - -C /target": Stream a directory to a remote machine without a temp file.zip -r archive.zip <dir>: Create a zip archive.unzip archive.zip: Extract a zip.unzip -l archive.zip: List zip contents.gzip <file>: Compress a single file: creates file.gz.gunzip <file>.gz: Decompress a .gz file.df -h: Disk space per filesystem, human-readable.du -sh <dir>: Total size of a directory.du -sh * | sort -rh | head -10: The 10 largest items in the current directory: disk cleanup.du -sh --max-depth=1 . | sort -rh: Size of each immediate subdirectory.fsck /dev/sda1: Check and repair a filesystem (run from recovery mode).mount /dev/sdb1 /mnt/data: Mount a partition.umount /mnt/data: Unmount a filesystem.Users & Network
whoami: Print the current user.id: Show user and group IDs.sudo -i: Open a root shell.sudo -u <user> <cmd>: Run a command as another user.useradd -m -s /bin/bash <name>: Create a user with home directory and shell.passwd <name>: Set a user's password.usermod -aG sudo <name>: Add a user to the sudo group: grant admin rights.userdel -r <name>: Delete a user and their home directory.groups: List groups the current user belongs to.ip addr: Show all network interfaces and IPs.ip route: Show the routing table.ping <host>: Check network reachability.curl -I https://www.www.devvkit.com: Fetch HTTP headers only: is the site up?curl -s https://api.github.com/repos/nodejs/node | jq .stargazers_count: Fetch JSON and extract a field with jq.wget -O file.zip https://example.com/file.zip: Download a file to a specific name.ss -tulpn: List listening ports and owning processes: what is running on port 3000?nc -zv <host> <port>: Test if a port is open.ssh <user>@<host>: Connect to a remote server.scp <file> <user>@<host>:<path>: Copy a file to a remote server.rsync -avz <src> <user>@<host>:<dst>: Sync directories to a remote: incremental, resume-friendly.System & Shell
uname -a: Kernel and system info.cat /etc/os-release: Which Linux distribution and version?uptime: How long has the system been up, and load average.free -h: Memory usage, human-readable.history: Show your command history.!!: Re-run the previous command.!<n>: Re-run command number n from history.alias ll='ls -la': Create a permanent shortcut (add to ~/.bashrc).export VAR=value: Set an environment variable for this session.echo $PATH: Show the executable search path.env: List all environment variables.shutdown -h now: Shut down the system.reboot: Restart the system.Frequently asked questions
How do I view disk and file size usage?
Use df -h for disk space per filesystem, du -sh <dir> for the total size of a directory, and du -sh * | sort -rh to rank the largest items in the current directory.
What does chmod 755 mean?
The three digits set permissions for owner, group, and others: 7 (rwx) for the owner, 5 (r-x) for the group, and 5 (r-x) for everyone else. Directories commonly use 755 so they remain traversable.
How do I find and kill a process?
Find it with ps aux | grep <name> or pgrep -a <name>, then terminate with kill <pid>. Use kill -9 <pid> only as a last resort, since it skips cleanup. pkill <name> kills by name pattern.
How do I search inside file contents?
Use grep -r "pattern" /path for recursive search, grep -ril for case-insensitive file listing, and combine with --include="*.js" to filter by file type. For speed, ripgrep (rg) is a modern alternative.