What is a command?
A command is a line of text you type to tell the server what to do. You type it in a terminal, a text window connected to the server. You usually connect with SSH, a safe way to open that window from your own computer.
Warning: Commands act at once and often have no undo. Back up before changing or deleting anything.
Looking around
pwd
Shows which folder you are in.
ls -la
Lists files and folders, including hidden ones.
cd /var/www
Moves into the folder /var/www.
Reading files
cat file.txt
Prints the file on screen.
tail -n 50 /var/log/messages
Shows the last 50 lines of a log file. Log file names differ by system.
Checking the server's health
df -h
Shows how much disk space is used and free.
free -m
Shows memory use in megabytes.
top
Shows which programs use the most power. Press q to leave.
uptime
Shows how long the server has been running and how busy it is.
Controlling the web server
On many systems, a service manager called systemd controls programs. The web server name may be httpd (Apache on CentOS-style systems), apache2 (Debian and Ubuntu) or nginx.
systemctl status nginx
Shows if the web server is running.
systemctl restart nginx
Stops and starts it again. Visitors may see a short break.
systemctl enable nginx
Makes it start by itself after a reboot.
Testing and searching
nginx -t
Checks the Nginx settings for mistakes before you restart. Apache has a similar one: apachectl configtest.
curl -I https://example.com
Shows the reply headers from your site. This helps you see the status code.
grep "error" file.log
Finds lines that contain the word "error".
ss -tulpn
Lists open ports and which program uses each.
Quick recap
- Commands are typed in a terminal, usually over SSH.
df,free,topanduptimecheck server health.systemctlstarts, stops and checks the web server.- Test settings before restarting.
- Back up before big changes.