Home › Guides › Reference › Linux Command Cheat Sheet

Linux Command Cheat Sheet

Essential Linux and Unix shell commands grouped by task: files, text, search, permissions, processes, disks and networking, with a worked example for each.

By the tools4free.dev team · Last reviewed 4 December 2026

How to read this cheat sheet

A shell command has the shape command [options] [arguments]. Options usually start with a dash: a short option is one letter after one dash (-l), and short options can be combined (-la means -l -a). Long options start with two dashes (--all). Arguments are the files, directories or text the command works on. Commands can be joined: a pipe (|) sends the output of one command into the next, > writes output to a file (replacing it), >> appends, and && runs the next command only if the first succeeded.

The tables below group the commands by task. Each row gives the command, what it does, and a typical example. Most of these are part of the GNU coreutils or are standard on every Linux distribution, and they behave the same on other Unix-like systems such as macOS with small differences in options. Commands that change or delete data are marked careful. Linux does not have a recycle bin at the command line, so a deleted file is usually gone.

The reference for any command is on your own machine: man <command> opens its manual page, and <command> --help prints a short summary. Online, the man7.org Linux man-pages and the GNU coreutils manual are the authoritative sources. To work out permission numbers, use the chmod calculator, to schedule jobs the cron builder, and for version control see the Git cheat sheet.

The commands you will use most

ls, cd, pwd, cp, mv, rm, mkdir, cat, less, grep, find, chmod, ps, kill, tar, ssh, man. Add sudo in front of a command to run it with administrator rights, only when you need to and understand the command.

Navigate and list

CommandWhat it doesExample
pwdPrints the current directory.pwd
lsLists directory contents. -l gives details, -a shows hidden files, -h gives readable sizes.ls -lah /var/log
cdChanges directory. cd alone goes to your home; cd - returns to the previous directory.cd ~/projects
treeShows a directory as a tree. Not installed everywhere.tree -L 2
duShows disk use of files and directories. -s summarises, -h is readable.du -sh *
dfShows free and used space on mounted file systems.df -h

Create, copy, move and delete

CommandWhat it doesExample
mkdirCreates a directory. -p creates parents and does not fail if it exists.mkdir -p site/css
touchCreates an empty file or updates a file's modification time.touch notes.txt
cpCopies files. -r copies directories recursively.cp -r src backup
mvMoves or renames files and directories.mv old.txt new.txt
rmDeletes files. -r deletes directories recursively. Careful: no undo. Add -i to confirm each file.rm -i old.log
rmdirDeletes an empty directory.rmdir empty-folder
ln -sCreates a symbolic link.ln -s /var/www/site current
rsyncCopies and synchronises files efficiently, locally or over SSH.rsync -av src/ backup/

View and process text

CommandWhat it doesExample
catPrints files, or joins them.cat a.txt b.txt
lessPages through a file. Press q to quit and / to search.less /var/log/syslog
headPrints the first lines, 10 by default.head -n 20 data.csv
tailPrints the last lines. -f follows a file as it grows.tail -f app.log
wcCounts lines, words and bytes. -l counts lines.wc -l data.csv
sortSorts lines. -n sorts numerically, -r reverses.sort -n numbers.txt
uniqRemoves adjacent duplicate lines. Sort first. -c counts them.sort names.txt | uniq -c
cutExtracts columns by delimiter or position.cut -d, -f1,3 data.csv
trTranslates or deletes characters.echo hello | tr a-z A-Z
sedEdits a stream of text, often to substitute.sed 's/foo/bar/g' file.txt
awkProcesses text by fields with small programs.awk '{print $1}' access.log
diffCompares two files line by line.diff -u old.txt new.txt

Search

CommandWhat it doesExample
grepFinds lines that match a pattern. -i ignores case, -r searches directories, -n shows line numbers.grep -rn "TODO" src/
findFinds files by name, type, size or date.find . -name "*.log" -mtime +30
whichShows the path of a command.which python3
locateFinds files by name using a prebuilt database. Not on every system.locate nginx.conf
whereisShows the binary, source and manual locations of a command.whereis ls

Quote patterns that contain * or other special characters, as in find . -name "*.log", so the shell passes them to the command instead of expanding them itself.

Permissions and ownership

Each file has permissions for its owner, its group and others. Read is 4, write is 2 and execute is 1, and you add them: 7 is rwx, 6 is rw-, 5 is r-x, 4 is r--. So 755 means rwxr-xr-x and 644 means rw-r--r--.

CommandWhat it doesExample
chmodChanges permissions, in numbers or symbols.chmod 755 script.sh
chmod +xMakes a file executable.chmod +x deploy.sh
chownChanges owner and group.sudo chown alice:staff report.txt
umaskShows or sets the default permission mask for new files.umask
sudoRuns a command as the superuser, or another user.sudo apt update
idShows your user and group IDs.id
whoamiPrints your user name.whoami
OctalSymbolicTypical use
644rw-r--r--Ordinary files, readable by everyone and writable only by the owner.
755rwxr-xr-xPrograms, scripts and directories.
600rw-------Private files such as SSH private keys.
700rwx------Private directories, for example ~/.ssh.

Processes

CommandWhat it doesExample
psLists processes. ps aux shows all processes with their owners.ps aux | grep nginx
topShows live process and resource use. Press q to quit.top
htopA friendlier version of top. Not installed everywhere.htop
killSends a signal to a process by its ID. The default is TERM, which asks it to stop.kill 1234
kill -9Sends KILL, which stops the process at once with no cleanup. Use as a last resort.kill -9 1234
pkillSends a signal by name.pkill firefox
jobsLists background jobs of the current shell.jobs
bg / fgResumes a stopped job in the background or foreground.fg %1
nohupRuns a command that survives the terminal being closed.nohup ./job.sh &
uptimeShows how long the system has run and the load averages.uptime
freeShows memory use. -h is readable.free -h

A trailing & starts a command in the background. Ctrl+C interrupts the foreground command, and Ctrl+Z suspends it.

Archives and compression

CommandWhat it doesExample
tar -czfCreates a gzip-compressed archive. c create, z gzip, f file name.tar -czf backup.tar.gz project/
tar -xzfExtracts a gzip-compressed archive.tar -xzf backup.tar.gz
tar -tfLists an archive without extracting.tar -tf backup.tar.gz
gzip / gunzipCompresses or decompresses one file.gzip big.log
zip / unzipCreates or extracts ZIP archives.unzip site.zip

Networking

CommandWhat it doesExample
pingChecks whether a host answers. Press Ctrl+C to stop, or use -c to limit packets.ping -c 4 example.com
curlTransfers data using URLs. -I shows only headers, -O saves with the remote name.curl -I https://example.com
wgetDownloads files.wget https://example.com/file.zip
sshLogs in to a remote machine securely.ssh user@host
scpCopies files over SSH.scp file.txt user@host:/tmp/
ip addrShows network interfaces and addresses.ip addr
ssShows sockets and listening ports. -tulpn lists listening TCP and UDP.ss -tulpn
digQueries DNS records. Part of the bind-utils or dnsutils package.dig example.com MX

HTTP codes returned by curl are explained in the HTTP status codes reference, and the port numbers shown by ss are listed in the common ports reference.

System information and packages

CommandWhat it doesExample
uname -aPrints kernel and system information.uname -a
datePrints or sets the date and time.date -u
historyShows previous commands.history | tail
manOpens the manual page for a command.man grep
echoPrints text or variables.echo "$HOME"
envPrints environment variables.env | sort
aptPackage manager on Debian and Ubuntu.sudo apt install curl
dnfPackage manager on Fedora and recent Red Hat systems.sudo dnf install curl
systemctlControls services on systems that use systemd.systemctl status nginx

Keyboard shortcuts in the shell

Common mistakes

Sources