Linux commands
Linux commands: the basics#
A short tutorial of only the commands used for this server. Each page is a list you can come back to:
| Page | For |
|---|---|
| Files and folders | Moving around, reading, copying, editing, searching |
| Permissions | ls -l, chmod, chown, sudo: who can read or change what |
| Hardware | CPU, memory, temperature, battery, USB devices |
| Disks and storage | Drives, free space, mounting, disk health |
| Network | Addresses, open ports, firewall, testing connections |
| SSH toolbox | Keys, shortcuts, copying files, tunnels, fixing errors |
| Services and logs | Starting/stopping programs, reading what went wrong |
| Software and users | Installing, updating, accounts, groups |
How to read a command#
sudo ls -l /srv/files
│ │ │ └── what to act on (a file or folder)
│ │ └─────── an option ("long list"); options start with -
│ └─────────── the command
└──────────────── "as administrator" (optional)
Six things that make the terminal easier#
| Do | How |
|---|---|
| Finish a name for you | Type the first letters, press Tab |
| Repeat an older command | Up (keep pressing to go further back) |
| Search old commands | Ctrl+R, type a word, Enter |
| Stop a running command | Ctrl+C |
| Clear the screen | clear or Ctrl+L |
| Help for a command | COMMAND --help, or man COMMAND (Q quits) |
Joining commands#
| Symbol | Meaning | Example |
|---|---|---|
| |
Send the output into the next command | ss -ltn | grep 8095 |
> |
Write the output into a file (replaces it) | ip a > network.txt |
>> |
Add the output to the end of a file | date >> log.txt |
&& |
Run the next one only if this one worked | sudo apt update && sudo apt upgrade |
~ |
Your home folder | cd ~ |
. and .. |
This folder, and the one above | cd .. |
* |
"Anything" in a name | ls *.pdf |
Paths#
/ the top of everything
/home/alex your home folder (also written ~)
/etc settings of the whole system
/srv data the server shares (files, backup, ai)
/var/log logs
/tmp temporary files (emptied at restart)
A path starting with / is absolute (from the top). Without / it's relative to the folder you're in. pwd tells you where you are.
Quotes
A name with spaces needs quotes: cat "my file.txt". Single quotes '...' keep everything exactly as typed; double quotes "..." still expand $VARIABLES.