ResourcesLinux Command Cheat Sheet

// Cheat SheetQuick Reference

Linux Command Cheat Sheet

A running reference of the Linux commands I find myself using or looking up most often — organized by category. Covers everyday file navigation, text processing, user and permission management, and networking. Commands are written for a typical Bash environment on Debian/Ubuntu or RHEL/Rocky; most will work on any modern Linux distro.

//Navigation & Files22 commands
CommandWhat it does
  • pwdPrint the full path of the current working directory
  • lsList files and directories in the current directory
  • ls -laList all files (including hidden) with detailed info
  • cd <dir>Change into a directory
  • cd ..Move up one directory level
  • cd ~Go to your home directory
  • mkdir <dir>Create a new directory
  • mkdir -p <path>Create a directory and any missing parent directories
  • touch <file>Create an empty file, or update its timestamp if it exists
  • cp <src> <dest>Copy a file from source to destination
  • cp -r <src> <dest>Copy a directory and all its contents recursively
  • mv <src> <dest>Move or rename a file or directory
  • rm <file>Delete a file permanently
  • rm -rf <dir>Delete a directory and everything in it — no confirmation
  • find <path> -name <pattern>Search for files matching a name pattern
  • find . -type f -mtime -7Find files modified in the last 7 days
  • locate <name>Fast file search using an indexed database
  • ln -s <target> <link>Create a symbolic (soft) link to a file or directory
  • stat <file>Show detailed metadata about a file
  • du -sh <dir>Show total disk usage of a directory in human-readable form
  • df -hShow available disk space on all mounted filesystems
  • treeDisplay directory structure as a visual tree
//Text & Search22 commands
CommandWhat it does
  • cat <file>Print the contents of a file to the terminal
  • less <file>View a file page by page — press q to quit
  • head -n <N> <file>Show the first N lines of a file
  • tail -n <N> <file>Show the last N lines of a file
  • tail -f <file>Stream a file as it grows — ideal for watching logs
  • grep <pattern> <file>Search for lines matching a pattern in a file
  • grep -r <pattern> <dir>Search for a pattern recursively across all files in a directory
  • grep -i <pattern>Case-insensitive pattern search
  • grep -v <pattern>Show lines that do NOT match the pattern
  • sed 's/old/new/g' <file>Replace every occurrence of old with new in a file (output only)
  • sed -i 's/old/new/g' <file>Replace text inside a file in place
  • awk '{print $1}' <file>Print the first field (column) of each line
  • cut -d: -f1 <file>Extract the first field using : as the delimiter
  • sort <file>Sort lines in a file alphabetically
  • sort -n <file>Sort lines numerically
  • uniqRemove consecutive duplicate lines (pipe from sort first)
  • sort | uniq -cSort and count how many times each unique line appears
  • wc -l <file>Count the number of lines in a file
  • wc -w <file>Count the number of words in a file
  • diff <file1> <file2>Show line-by-line differences between two files
  • echo <text>Print text to the terminal or redirect it into a file
  • tee <file>Write stdin to both stdout and a file simultaneously
//Permissions & Users22 commands
CommandWhat it does
  • whoamiPrint the name of the currently logged-in user
  • idShow your user ID, primary group ID, and all group memberships
  • groupsList all groups the current user belongs to
  • sudo <command>Run a command with superuser (root) privileges
  • sudo -iOpen an interactive root shell
  • su - <user>Switch to another user account
  • chmod 755 <file>Set rwxr-xr-x permissions — owner can write, others can read and execute
  • chmod +x <file>Make a file executable
  • chmod -R 644 <dir>Apply permissions recursively to all files in a directory
  • chown <user> <file>Change the owner of a file
  • chown <user>:<group> <file>Change both the owner and group of a file
  • chown -R <user>:<group> <dir>Change owner and group recursively
  • useradd -m <user>Create a new user with a home directory
  • userdel -r <user>Delete a user and remove their home directory
  • usermod -aG <group> <user>Add a user to a group without removing existing groups
  • passwd <user>Set or change a user password
  • groupadd <group>Create a new group
  • visudoSafely edit the sudoers file with syntax validation
  • lastShow recent login history for all users
  • umask 022Set the default permissions mask for newly created files
  • ls -l <file>View the permission string, owner, and group of a file
  • stat <file>Show full permission details including octal notation
//Networking22 commands
CommandWhat it does
  • ip addr showShow all network interfaces and their IP addresses
  • ip route showDisplay the routing table
  • ip link set <iface> upBring a network interface up
  • ping <host>Test basic network connectivity to a host
  • ping -c 4 <host>Send exactly 4 ping packets then stop
  • traceroute <host>Show the route packets take to reach a host
  • ss -tulnpShow all listening TCP/UDP ports and the process using each
  • ss -sShow a summary of socket statistics
  • curl <url>Fetch content from a URL
  • curl -I <url>Fetch only the HTTP response headers from a URL
  • curl -O <url>Download a file, preserving the remote filename
  • wget <url>Download a file from a URL
  • wget -r <url>Recursively download an entire website
  • ssh <user>@<host>Open a secure shell session on a remote host
  • ssh -i <key> <user>@<host>Connect to a remote host using a private key file
  • scp <file> <user>@<host>:<path>Securely copy a file to a remote host
  • scp -r <dir> <user>@<host>:<path>Securely copy a directory to a remote host
  • dig <domain>Perform a full DNS lookup for a domain
  • dig +short <domain>Quick DNS lookup — returns only the answer
  • nslookup <domain>Query a DNS server interactively
  • nmap -sV <host>Scan a host and detect service versions on open ports
  • ufw statusShow the current firewall rules and status

// A Note on Usage

Commands marked with angle brackets like <file> expect you to substitute your actual value. Commands that destructively modify data (rm -rf, sed -i) should be tested with a dry run or on a copy first. When in doubt, man <command> opens the full manual page.

This is a personal reference, not a comprehensive manual. If you spot an error or a command that should be here, reach out via the contact page.