Linux Commands Cheat Sheet
The commands you use every day, grouped by job, each with a short example.
The commands you use every day, grouped by job, each with a short example. Press Try to run one in a practice terminal right here, or print the page for your desk.
A practice shell in your browser that behaves like bash on Linux for these commands. Nothing you type leaves the page.
Files and folders
cd projectsgo into a folder (cd .. goes up, cd goes home) Lesson 2
mkdir -p notes/2026make a folder and any missing parents Lesson 4
touch todo.txtcreate an empty file Lesson 4
cp report.txt copy.txtcopy a file (cp -r for a folder) Lesson 5
mv draft.txt final.txtrename or move a file Lesson 5
rm old.txtdelete a file, for good Lesson 6
rm -r builddelete a folder and everything in it Lesson 6
ln -s notes.txt latest.txtmake a symbolic link (a shortcut) Lesson 18
Viewing files
cat notes.txtprint a whole file Lesson 3
less app.logscroll through a file (q quits) Lesson 17
head -n 5 notes.txtthe first 5 lines Lesson 7
tail -n 5 app.logthe last 5 lines (tail -f follows a log) Lesson 7
wc -l notes.txtcount the lines Lesson 12
diff -u shopping.txt shopping-new.txtshow what changed between two files Lesson 23
Searching
grep error app.loglines that contain a word Lesson 13
grep -rin todo projectssearch every file in a folder, any case, with line numbers Lesson 13
grep -v INFO app.loglines that do NOT match Lesson 13
find . -name "*.txt"find files by name Lesson 15
find . -type d -emptyfind empty folders Lesson 15
which tarwhere a program lives
Working with text
sort -n scores.txtsort lines by number (-r reverses) Lesson 12
sort fruit.txt | uniq -ccount each line Lesson 12
cut -d, -f1 data.csvone column of a CSV file Lesson 21
awk -F, '{print $2}' data.csvprint a column; awk can also filter and add up Lesson 36
sed 's/pear/apple/g' fruit.txtfind and replace (sed -i edits the file) Lesson 22
tr a-z A-Z < names.txtchange characters, here to upper case Lesson 21
ls | tee listing.txtsee output and save it to a file Lesson 1
ls *.tmp | xargs rmrun a command on each name in a list Lesson 1
echo "hi" >> notes.txtadd a line to the end of a file (> replaces it) Lesson 1
Permissions
ls -l backup.shsee who may read, write and run a file Lesson 1
chmod u+x backup.shlet yourself run a script Lesson 10
chmod 644 report.txtrw-r--r--: you change it, others read it Lesson 10
chmod 755 binrwxr-xr-x: the usual for folders and programs Lesson 10
sudo chown www-data report.txtgive a file to another user Lesson 41
sudo apt updaterun a command as the administrator Lesson 41
Processes
sleep 60 &run a command in the background
historythe commands you typed (!! runs the last one)
Networking
ping -c 3 example.comcheck that a machine answers Lesson 30
curl -I https://example.comfetch a web page’s headers (curl -O downloads) Lesson 30
ssh learner@weblog in to another machine as a user (exit comes back) Lesson 31
scp notes.txt learner@web:~copy a file to another machine Lesson 31
dig example.comlook up a name’s IP address (DNS) Lesson 46
Archives and disk space
tar -czf backup.tar.gz projectspack a folder into a .tar.gz Lesson 20
tar -tzf website-2025.tar.gzlist what is in an archive Lesson 20
tar -xzf website-2025.tar.gzunpack an archive here Lesson 20
gzip -k server.logcompress one file (gunzip undoes it) Lesson 20
du -sh projectshow much space a folder takes Lesson 19
The shell itself
alias ll='ls -alF'a short name for a long command Lesson 25
export EDITOR=nanoset an environment variable Lesson 24
echo $PATHwhere the shell looks for programs Lesson 1
source ~/.bashrcreload your shell settings Lesson 25
clearclear the screen (Ctrl+L)
Vim basics
vim notes.txtopen a file in Vim Lesson 28
Learn them by typing them
Every command name above links to its page, with its options and worked examples. To learn them in order, with a practice terminal that checks your work, start the free course: Learn Linux.
Common questions
What are the most important Linux commands to learn first?
pwd, ls and cd to find your way around; mkdir, touch, cp, mv and rm to manage files; cat, less, head and tail to read them; and grep to search. With those and the | pipe you can do most everyday work.
Do these commands work on a Mac?
Almost all of them. macOS has the same commands from BSD, so a few options differ: sed -i needs an empty argument there (sed -i '' ...), and some GNU long options are missing.
How do I print this cheat sheet?
Use your browser’s Print (Ctrl+P or ⌘+P). The page prints as a compact sheet without the menus and buttons, on one or two pages.
Where can I practise these commands safely?
Press Try beside a command to run it in a practice terminal on this page, with sample files you can’t harm, or take the free Linux lessons, which check your work as you go.