Linux Commands Cheat Sheet: 60 Commands by Task
A Linux commands cheat sheet grouped by what you're trying to do: files, permissions, users, processes, disk, network, services, logs and packages.

On this page 11 sections ▾
TL;DR
- You don't need to memorize these. Find the job you're doing, copy the command, and swap in your own file or folder names.
- Stuck on any command?
man <command>opens its manual, and most commands also explain themselves with--help. - Commands that start with
sudorun as the administrator and can change the whole system, so read them twice before you press Enter.
Bookmark this one. It's a Linux commands cheat sheet sorted by the job in front of you, not by the alphabet: find the task, grab the command, and get on with your day. Nearly all of it works on any Linux system; the apt package commands are the Ubuntu and Debian way of installing software.
Quick facts
A "hidden" file in Linux is just a file whose name starts with a dot, like .bashrc. Plain ls skips them and ls -a shows them.
cd - takes you straight back to the folder you were in before, like a back button.
rm has no trash can. A deleted file doesn't go anywhere you can restore it from with a click.
usermod -G without -a doesn't just add a group: it removes the user from every group you didn't list.
#Getting around (and getting help)
- pwdShows the full path of the folder you're in right now.
- lsLists what's in the current folder.
- ls -laLists everything, hidden files included, with permissions, owner, size and date.
- cd folderMoves you into a folder.
cdon its own takes you home. - cd ..Moves you up one folder.
- cd -Jumps back to the folder you were in before.
- man commandOpens the manual for a command. Press
qto quit,/to search.
$ pwd /home/alex $ mkdir -p projects/site $ cd projects/site $ pwd /home/alex/projects/site $ cd - /home/alex
#Files and folders
- mkdir -p a/b/cMakes a folder, plus any missing folders above it, with no error if it already exists.
- touch file.txtCreates an empty file, or updates the timestamp on one that exists.
- cp file.txt copy.txtCopies a file.
- cp -r folder backupCopies a folder and everything inside it.
- mv old.txt new.txtRenames a file, or moves it if you give a folder as the second name.
- rm file.txtDeletes a file.
- rm -r folderDeletes a folder and everything in it. Add
-ito be asked before each file.
$ mkdir -p ~/notes $ cd ~/notes $ touch todo.txt $ cp todo.txt todo.bak $ mv todo.bak old.txt $ ls old.txt todo.txt $ rm old.txt $ ls todo.txt
#Reading files
- cat file.txtPrints a whole file. Best for short ones.
- less file.txtOpens a long file one screen at a time. Arrow keys scroll,
qquits. - head -n 20 file.txtShows the first 20 lines. Leave out
-nand you get 10. - tail -n 20 file.txtShows the last 20 lines, where the newest entries in a log usually are.
- tail -f app.logKeeps the file open and prints new lines as they're added, so you can watch a log live.
Ctrl+Cstops it. - wc -l file.txtCounts the lines in a file.
#Searching
- grep "error" app.logPrints every line in the file that contains the word. Add
-nfor line numbers. - grep -ri "error" /var/logSearches every file in a folder and the folders inside it, ignoring upper and lower case.
- find . -name "*.log"Finds files by name, starting from the current folder.
*matches anything. - which python3Shows where a command's program lives. No output means it isn't installed, or isn't anywhere your shell looks for commands.
- historyLists the commands you've run. Pipe it into grep to find one:
history | grep ssh.
$ head -n 2 app.log start ok error: disk full $ grep -n error app.log 2:error: disk full 4:error: timeout $ wc -l app.log 4 app.log
#Permissions and users
- chmod +x script.shMakes a file executable, so you can run it with
./script.sh. - chmod 644 file.txtSets permissions by number: here the owner can read and write, and everyone else can only read.
- sudo chown alex:alex file.txtChanges who owns a file (user, then group).
- sudo commandRuns a single command as the administrator (root).
- whoamiPrints the user you're logged in as.
- idShows your user ID and every group you belong to.
- sudo useradd -m samCreates a new user with a home folder.
- sudo passwd samSets or changes a user's password.
- sudo usermod -aG docker samAdds a user to a group. The
-amatters: without it,-Greplaces all of their other groups. The change applies the next time they log in.
$ ls -l deploy.sh -rw-rw-r-- 1 alex alex 26 Nov 7 23:15 deploy.sh $ chmod +x deploy.sh $ ls -l deploy.sh -rwxrwxr-x 1 alex alex 26 Nov 7 23:15 deploy.sh $ ./deploy.sh deployed
ELI5: explain it simply▾

THE WORDS
- Permissions
- Rules for who can read a file, change it, or run it as a program.
- rwx
- Read, write and execute. A dash means that permission is off.
- Executable
- A file Linux is allowed to run as a program.
THE IDEA
Think of -rw-rw-r-- as three sets of keys: one for the owner, one for their group, and one for everyone else. Before chmod +x, nobody holds the "run it" key. After it, every set has an x in it, so the script can run.
#Processes
- ps auxLists every running process, with its owner, process ID (PID), CPU and memory use.
- topA live, updating view of what's using the most CPU and memory.
qquits. - kill 1234Asks the process with that PID to stop.
kill -9 1234forces it if it won't. - pkill nameStops processes by name instead of by PID. It matches part of a name too, so check what it will hit with
pgrep -l namefirst.
$ sleep 300 & [1] 369 # the [s] stops grep from listing itself $ ps aux | grep [s]leep alex 369 0.0 0.0 3136 2008 pts/0 S 23:19 0:00 sleep 300 $ pgrep -l sleep 369 sleep $ pkill sleep [1]+ Terminated sleep 300 $ ps aux | grep [s]leep # no output: the process is gone
#System and disk
- df -hShows how full each disk is, in sizes like G and M.
- du -sh folderShows the total size of one folder.
- free -hShows how much memory is used and available.
- uname -aPrints the kernel version and other system details.
- uptimeShows how long the system has been running and how busy it's been.
#Networking
- ip aShows your network interfaces and their IP addresses.
- ping -c 4 example.comSends 4 test packets to check whether a host answers and how fast.
- curl https://example.comFetches a web page or API response and prints it. Add
-Ito see only the headers. - ss -tulpnLists the TCP and UDP ports listening for connections, with the program using each (run with
sudoto see them all). - ssh alex@serverOpens a terminal on another machine over an encrypted connection.
- scp file.txt alex@server:~/Copies a file to another machine over SSH.
#Services and logs
- systemctl status nginxShows whether a service is running, plus its latest log lines.
- sudo systemctl restart nginxStops and starts a service, usually after you change its config.
- sudo systemctl enable --now nginxMakes a service start at boot, and
--nowstarts it right away too. - journalctl -u nginxShows the logs for one service. Add
--since todayto cut it down. - journalctl -fFollows the system log live, like
tail -ffor everything.
#Packages and archives
- sudo apt updateRefreshes the list of available packages. It doesn't install anything by itself.
- sudo apt upgradeUpgrades the packages you already have to their newest available versions.
- sudo apt install nginxInstalls a package. On Fedora and Red Hat systems, the same job is
sudo dnf install. - tar -czf backup.tar.gz folderPacks a folder into one compressed file: c for create, z for gzip, f for the file name.
- tar -xzf backup.tar.gzUnpacks it again into the current folder (x for extract). Use
-tzfto list what's inside first. - unzip file.zipUnpacks a .zip file into the current folder. If it's not installed,
sudo apt install unzipadds it.
$ tar -czf site-backup.tar.gz projects/site $ tar -tzf site-backup.tar.gz projects/site/ projects/site/index.html projects/site/deploy.sh projects/site/app.log $ ls -lh site-backup.tar.gz -rw-rw-r-- 1 alex alex 262 Nov 7 23:15 site-backup.tar.gz
#Going past the Linux commands cheat sheet
A cheat sheet tells you what to type. It doesn't build the habit of knowing which command to reach for, and that only comes from using them on something. A spare PC or a virtual machine running Ubuntu is plenty, and our homelab projects for your resume give you a reason to use all of this.

Run these commands step by step
Linux Fundamentals, Level 1 of every ProCourse, is where you actually do this, with labs and quizzes in a simulated terminal in your browser. Level 1 is free.
What are the most basic Linux commands?
pwd, ls, cd, mkdir, cp, mv and rm cover moving around and handling files, which is most of what you'll do at first.How do I learn what a Linux command does?
man followed by the command name to open its manual, or add --help to the command for a shorter summary of its options.Do these commands work on a Mac?
ls, cd, cp, grep and tar all work. Linux-only tools like apt, systemctl, journalctl and ip don't, and some options differ.Can I undo rm in Linux?
rm doesn't use a trash can, so the safe habits are rm -i to be asked first, and a backup of anything you'd miss.