Files and directories
| Command | What it does |
|---|
pwd / cd dir / cd - | where am I / go there / go back |
ls -la | list everything, with permissions and owners |
cp -r a b / mv a b / rm -r dir | copy / move or rename / delete a tree |
mkdir -p a/b/c | make a path, parents included |
find / -name '*.conf' 2>/dev/null | find files by name |
cat, less, head -n 20, tail -f | read a file, page it, start, follow |
du -sh dir / df -h | size of a directory / free disk |
Permissions and ownership
| Command | What it does |
|---|
chmod 644 f / chmod u+x f | set by number / add by letter |
chmod -R g+rX dir | group may read a tree and enter directories |
chown user:group f | change owner and group |
umask | the default permissions new files lose |
id / groups | my user, my groups |
Numbers: r=4 w=2 x=1, per owner/group/other. 755 programs, 644 files, 600 secrets.
Users
| Command | What it does |
|---|
sudo -i / sudo cmd | root shell / one command as root |
useradd -m -s /bin/bash name | create a user with a home |
usermod -aG group name | add to a group (log in again to see it) |
passwd name | set a password |
getent passwd name | look a user up |
Processes and services
| Command | What it does |
|---|
ps aux / top | every process / live view |
pgrep -a name / kill PID / kill -9 PID | find / ask to stop / force stop |
| `systemctl status | start |
systemctl enable --now nginx | start now and at boot |
journalctl -u nginx -f | follow a service's log |
Networking
| Command | What it does |
|---|
ip a / ip r | addresses / routes |
ss -tlnp | listening TCP ports and their programs |
ping -c 3 host | is it reachable |
curl -I https://site | HTTP headers only |
getent hosts name / dig name | resolve a name |
nmap -sV host | scan ports and versions (only hosts you may scan) |
Shell habits
Ctrl+R search history · !! last command · cmd > file write, >> file append, 2>&1 errors too · cmd | less · man cmd · cmd --help.