Skip to content

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 ​

CommandExampleWhat it does
pwdpwdPrints the folder you are in
lslsLists files, in colour
llllLong list with details and hidden files (ls -alF)
lalaLists hidden files too (ls -A)
llCompact list with type markers (ls -CF)
cdcd DocumentsChanges folder
mkdirmkdir my-appCreates a folder
touchtouch notes.txtCreates an empty file
cpcp a.txt b.txtCopies a file
mvmv old.txt new.txtMoves or renames
rmrm file.txtDeletes a file
rm -rfrm -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 ​

TypeTo 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 ​

CommandExampleWhat it does
catcat notes.txtPrints the whole file
headhead -n 20 log.txtPrints the first lines
tailtail -n 20 log.txtPrints the last lines
lessless log.txtOpens a pager. Arrow keys scroll, /word searches, q quits
moremore log.txtA simpler pager
wcwc -l log.txtCounts lines, words and characters

Search and process text ​

CommandExampleWhat it does
grepgrep -i error log.txtPrints lines that contain a word. Matches are coloured
findfind . -name "*.txt"Finds files by name, below the current folder
sortsort names.txtSorts lines
uniqsort names.txt | uniqRemoves repeated lines next to each other
sedsed 's/old/new/g' file.txtReplaces text as it prints
awkawk '{print $1}' file.txtPrints chosen columns

Combine commands ​

Pipes and redirects work as on Linux.

SymbolExampleWhat it does
|ls | grep txtSends the output of one command to the next
>ls > files.txtWrites output to a file, replacing its contents
>>echo done >> log.txtAdds output to the end of a file
<sort < names.txtReads input from a file

A worked example: count how many lines in a log mention "error", ignoring upper and lower case.

bash
grep -i error app.log | wc -l

Clear the screen and stop a command ​

To do thisUse
Clear the screenclear or cls
Stop a running commandCtrl + C
Bring back earlier commandsUp and down arrows
Complete a nameTab
Close the shellexit

Get help on a command ​

Most commands print their options when you add --help:

bash
grep --help

The 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.

Next steps ​