These are the commands I reach for most often on Ubuntu. Lines beginning with $ are what you type.

Installing software

On current Ubuntu, apt is the friendly command to use. The older apt-get still works and is common in scripts.

$ sudo apt update            # refresh the list of available packages
$ sudo apt upgrade           # install available updates
$ sudo apt install nginx     # install a package
$ sudo apt remove nginx      # remove a package

Moving around and looking at files

$ pwd                # show the folder you are in
$ cd /var/www        # change folder
$ cd ..              # go up one level
$ ls -la             # list files, including hidden ones, with details
$ cat notes.txt      # print a file
$ grep "error" app.log   # find lines containing a word

Creating and editing

$ mkdir projects          # make a folder
$ touch notes.txt         # create an empty file
$ nano notes.txt          # edit in a simple editor (Ctrl+O saves, Ctrl+X exits)
$ cp notes.txt backup.txt # copy
$ mv backup.txt old/      # move or rename

Permissions

$ chmod 644 notes.txt     # owner can read and write, others can read
$ chmod +x script.sh      # make a script executable

Avoid chmod 777. It lets everyone change the file, which is rarely what you want.

Networking and remote access

$ ping -c 4 example.com        # check you can reach a host (four attempts)
$ ssh user@server.example.com  # log in to another machine

Archives

$ tar -czf site.tar.gz site/   # create a compressed archive
$ tar -xzf site.tar.gz         # extract it

Checking your system

$ history        # list recent commands
$ df -h          # disk space, in readable units
$ free -h        # memory use
$ top            # live view of running processes (press q to quit)

Quick reference

Command What it does
apt update / install / remove Manage software
cd, ls, pwd Move around and look
mkdir, touch, cp, mv Create, copy and move
cat, grep, nano Read, search and edit
chmod Change permissions
ping, ssh Networking
tar Archives
history, df, free, top Check the system

Add --help to most commands, or use man command, to see every option.