A quick reference for working on a server: files and folders, permissions, disk space, processes, services, logs and networking.
Contents
The commands you will need most often when working on a server over SSH. For detailed help on any command, use man command or command --help.
Files and folders
pwd | where am I now |
ls -la | the contents of a folder, including hidden files, with permissions and sizes |
cd /var/www, cd ~, cd - | go to a folder, to your home folder, to the previous folder |
mkdir -p a/b/c | create a folder along with any missing parent folders |
cp -a source destination | copy, keeping permissions and dates; works for folders too |
mv source destination | move or rename |
rm file, rm -r folder | delete a file or a folder |
cat, less | show a file in full, or page by page (to quit less, press q) |
tail -f /var/log/file | follow the end of a file, such as a log (press Ctrl+C to stop) |
Searching
find /var/www -name '*.php' -mtime -1 | .php files changed in the last 24 hours |
grep -rn 'text' /etc/nginx/ | lines containing the text in all files in a folder, with line numbers |
command -v php | where a program is located — more in Finding where a program is located |
Permissions and owners
chmod 644 file | read and write for the owner, read for everyone else — the usual permissions for a file |
chmod 755 folder | the same, plus entering the folder or running it — the usual permissions for a folder or script |
chown -R www-data:www-data /var/www/site | change the owner of a folder and everything in it |
sudo command | run a command with administrator rights |
For what the permission numbers mean and how to set permissions on website files, see File permissions: chmod and chown.
Disk space and memory
df -h | how much space is used and free on your disks |
du -sh /var/* | sort -h | which folders take up the most space — the largest at the bottom |
free -h | memory (RAM) |
If your disk is full and you need to know what can be deleted, see Out of disk space.
Processes
top | what is using the CPU and memory right now (to quit, press q); htop is easier to use, if it is installed |
ps aux | grep nginx | find processes by name |
kill 1234 | end a process by its number — more in Which program is using a port |
To work out what is holding your server back, see Slow server: how to find the cause.
Services and logs
systemctl status nginx | whether a service is running, and the last lines of its log |
sudo systemctl restart nginx | restart it; reload re-reads the settings without stopping it |
sudo systemctl enable --now nginx | start it and make it start at boot |
journalctl -u nginx -n 50 | the last 50 lines of a service’s log; -f keeps following it |
To see the log for a particular hour, errors only, or the previous boot, see Logs: journalctl and /var/log.
Network
ip -4 addr, ip route | the server’s addresses and gateway |
sudo ss -ltnp | which programs are listening on which ports |
ping -c 4 hosting-telecom.uk | whether an address is reachable |
curl -I https://website | a website’s response: status code and headers |
dig website A +short | a DNS record (the dnsutils package on Debian and Ubuntu, bind-utils on AlmaLinux) |
Archives
tar -czf site.tar.gz /var/www/site | pack a folder into an archive |
tar -xzf site.tar.gz | unpack into the current folder |
For zip, other kinds of compression and exclusions, see Archives: tar, gz and zip. To copy files to another server, see rsync.
Updating the system
| Ubuntu, Debian | sudo apt update && sudo apt upgrade |
| AlmaLinux | sudo dnf upgrade |
| FreeBSD | sudo pkg upgrade — in our images this updates both the system and your software (more in FreeBSD on a cloud server) |
Keyboard shortcuts make the command line easier to work with — they are collected in Command-line keyboard shortcuts.
Run long commands in tmux: if your SSH connection drops, they will carry on and finish.
Didn’t find the answer? Ask our support team — we’ll help.