Linux Command Cheatsheet

Common Linux terminal commands for file management and system administration.

Everyday Linux shell commands with a plain explanation of each: moving around folders, listing, copying, moving and deleting files, reading and searching files, permissions, processes, disk space, networking and archives. The same commands work in the macOS Terminal and in Windows Subsystem for Linux, with small differences in some options. Search the table for a word like "delete", "search" or "disk". Take care with rm: there's no recycle bin in the shell, so a deleted file is gone. For patterns in grep and find, the Regex Cheat Sheet helps.

Linux shell commands

CommandWhat it does
pwdPrint the current directory
ls -laList all files with details
cd <dir>Change directory (cd .. goes up, cd ~ goes home)
mkdir -p <dir>Create a directory and any parents
cp -r <src> <dst>Copy files or folders
mv <src> <dst>Move or rename
rm <file> / rm -r <dir>Delete a file / a folder (no undo)
touch <file>Create an empty file or update its timestamp
cat / less <file>Print / page through a file
head -n 20 / tail -f <file>First 20 lines / follow a growing log
grep -rn "text" <dir>Search file contents recursively
find . -name "*.log"Find files by name
chmod 755 <file>Set permissions (owner rwx, others rx)
chown user:group <file>Change owner
sudo <command>Run as administrator
ps aux / topList processes / live view
kill <pid> / kill -9 <pid>Stop a process / force it
df -h / du -sh <dir>Disk free space / size of a folder
tar -czf a.tar.gz <dir>Create a compressed archive
tar -xzf a.tar.gzExtract it
curl -O <url>Download a file
ssh user@hostLog in to a remote machine
historyShow previous commands
man <command>Read a command's manual

Common use cases

  • Look up a command while working on a server
  • Learn the terminal as a beginner
  • Remember options for find, grep, tar and chmod
  • Keep a quick reference open for coursework

How to use

  1. Search for what you want to do.
  2. Copy the command and replace the parts in angle brackets.
  3. Add --help to most commands, or run man <command>, for every option.

FAQ

What does sudo do?

It runs one command as the administrator (root). Use it only when a command needs it, such as installing software, because root can change or delete anything.

How do chmod numbers like 755 work?

Each digit is the owner, group and everyone else, adding read (4), write (2) and execute (1). 755 means the owner can do everything and others can read and run; 644 means the owner can read and write and others can only read.

Do these commands work on a Mac?

Almost all of them. macOS uses BSD versions of some tools, so a few options differ (for example sed -i needs an extra argument), but the commands and basic use are the same.

Can I undo rm?

Not from the shell. rm deletes without a recycle bin, so check the path first, and use rm -i to be asked before each file is removed.