Everyday commands
The commands you use most on a Linux command line, as they work in Ubuntu Terminal. Type helpme in the app for a short version of this page.
Files and folders
| Command | Example | What it does |
|---|---|---|
pwd | pwd | Prints the folder you are in |
ls | ls | Lists files, in colour |
ll | ll | Long list with details and hidden files (ls -alF) |
la | la | Lists hidden files too (ls -A) |
l | l | Compact list with type markers (ls -CF) |
cd | cd Documents | Changes folder |
mkdir | mkdir my-app | Creates a folder |
touch | touch notes.txt | Creates an empty file |
cp | cp a.txt b.txt | Copies a file |
mv | mv old.txt new.txt | Moves or renames |
rm | rm file.txt | Deletes a file |
rm -rf | rm -rf folder/ | Deletes a folder and everything in it |
DANGER
rm and rm -rf delete permanently. Nothing goes to the Recycle Bin. rm -rf does not ask for confirmation.
To copy a folder with its contents, add -r: cp -r project project-copy.
Move around faster
| Type | To go |
|---|---|
cd or ~ | To your user folder |
.. | Up one level |
... | Up two levels |
cd - | Back to the folder you were in before |
~ at the start of a path means your user folder, so ~/Documents is your Documents folder.
Names with spaces need quotes: cd "My Projects".
Look inside files
| Command | Example | What it does |
|---|---|---|
cat | cat notes.txt | Prints the whole file |
head | head -n 20 log.txt | Prints the first lines |
tail | tail -n 20 log.txt | Prints the last lines |
less | less log.txt | Opens a pager. Arrow keys scroll, /word searches, q quits |
more | more log.txt | A simpler pager |
wc | wc -l log.txt | Counts lines, words and characters |
Search and process text
| Command | Example | What it does |
|---|---|---|
grep | grep -i error log.txt | Prints lines that contain a word. Matches are coloured |
find | find . -name "*.txt" | Finds files by name, below the current folder |
sort | sort names.txt | Sorts lines |
uniq | sort names.txt | uniq | Removes repeated lines next to each other |
sed | sed 's/old/new/g' file.txt | Replaces text as it prints |
awk | awk '{print $1}' file.txt | Prints chosen columns |
Combine commands
Pipes and redirects work as on Linux.
| Symbol | Example | What it does |
|---|---|---|
| | ls | grep txt | Sends the output of one command to the next |
> | ls > files.txt | Writes output to a file, replacing its contents |
>> | echo done >> log.txt | Adds output to the end of a file |
< | sort < names.txt | Reads input from a file |
A worked example: count how many lines in a log mention "error", ignoring upper and lower case.
grep -i error app.log | wc -lClear the screen and stop a command
| To do this | Use |
|---|---|
| Clear the screen | clear or cls |
| Stop a running command | Ctrl + C |
| Bring back earlier commands | Up and down arrows |
| Complete a name | Tab |
| Close the shell | exit |
Get help on a command
Most commands print their options when you add --help:
grep --helpThe commands come from BusyBox, a compact toolkit. They cover the common options, but a few rarely used options from full Linux systems are missing. If an option from a tutorial is rejected, check --help for what is supported.