Wiki
Home › Root servers › Everyday commands

Everyday commands

The most important Linux commands for vServer and dedicated servers.

These commands work on Debian and Ubuntu. They are sorted by task. Commands with sudo are meant for a normal user. As root, leave out sudo.

Only run commands when you are clear what they do. Never copy deletion commands such as rm -rf without checking the path first. A mistyped path can delete entire directories.

Overview of the server

uptimeUptime and load. The three numbers are the load over the last 1, 5 and 15 minutes. If they stay above the number of cores (nproc), the server is overloaded.
htopProcesses, CPU and RAM usage live. Quit with q. Installation: sudo apt install htop
free -hMemory and swap. The column available matters most. The value free is often small, because Linux uses free memory as cache.
nprocNumber of CPU cores
hostnamectlHostname, operating system and kernel version

Storage and disks

df -hUsage of the file systems. If a partition is at 100 %, services often fail.
df -iUsed inodes. Many tiny files can use up the space even though df -h still shows free storage.
du -sh /path/*Size of the folders in a directory. Sorted and without errors on permissions: sudo du -sh /var/* | sort -h
lsblkDisks and partitions as a tree
sudo journalctl --disk-usageStorage used by the logs. Shrink to seven days with sudo journalctl --vacuum-time=7d.

Manage services

systemctl status serviceState, latest log lines and start time of a service
sudo systemctl restart serviceRestart the service completely. Existing connections are dropped.
sudo systemctl reload serviceReload the configuration without stopping the service. Useful for SSH, so the open session stays.
sudo systemctl enable --now serviceStart the service at boot and start it immediately
sudo systemctl disable --now serviceStop the service and disable it at boot
systemctl --failedAll services that ended with an error. Worth a look after a reboot.

Read logs

journalctl -u service -n 100Last 100 log lines of a service
journalctl -u service -fFollow the logs of a service live, stop with Ctrl+C
journalctl --since "1 hour ago"All logs of the last hour
tail -f /path/to/logFollow a log file live, e.g. /var/log/nginx/error.log
sudo grep -i error /var/log/syslogFind lines containing a search term. Upper and lower case do not matter with -i.

Network

ip -br aNetwork addresses, short and clear. The IPv4 and IPv6 addresses of the interfaces.
ip rRouting table. Shows through which gateway the server reaches the network.
sudo ss -tulpnOpen ports and the program behind them. An unknown service on an open port is a warning sign.
ping -c 4 example.comCheck reachability. Four packets, then stop.
curl -I https://example.comOnly the HTTP headers of a web page. Shows the status code, e.g. 200 OK.
dig +short example.comCheck the DNS record of a domain. Requires the package dnsutils.

Install and update packages

sudo apt update && sudo apt upgrade -yFetch package lists and update all packages. Details in the section Updates.
sudo apt install -y packageInstall a package. With -y without asking.
apt list --upgradableShows which packages have an update
sudo apt autoremoveRemove packages that are no longer needed

Files and folders

ls -la /pathAll files including hidden ones, with permissions and owner
cp -r source targetCopy a folder, -r for recursive
mv old newMove or rename
grep -R "text" /pathSearch all files in a folder for a text
find /path -name "*.log" -mtime +7Find files matching the pattern that are older than seven days. Only searches, does not delete.
chmod 600 fileOnly the owner may read and write. Needed for private keys.
chown user:group fileChange the owner of a file

Editor nano

Files on the server are usually edited with nano file. Save with Ctrl+O, exit with Ctrl+X. Search for text with Ctrl+W.

Processes

ps aux --sort=-%mem | head -n 10The ten processes using the most memory
sudo kill PIDEnd a process by its process number (PID). The PID is shown in htop or ps.
tmuxA session that keeps running after the connection drops. Ideal for long tasks. Installation: sudo apt install tmux

Who is logged in?

whoLogged-in users
last -n 20Last successful logins
sudo lastb -n 20Last failed logins. Useful for spotting attacks on SSH. fail2ban (see fail2ban) should catch them.

Security

sudo ufw status verboseShow firewall rules, see Firewall
sudo fail2ban-client status sshdShow blocked addresses
sudo sshd -tCheck the SSH configuration for errors before reloading the service

Reboot

sudo rebootRestart the server immediately. First check whether a reboot is needed (see Updates) and whether someone is working on it.
sudo shutdown -r +5Restart in five minutes. Cancel with sudo shutdown -c.

Help for a command

Use man command to open the manual page. command --help gives a short overview. Leave the manual page with q.