Tutorials

25 Linux commands every site owner should know

Learn 25 essential Linux commands for server management: file management, processes, network, and disk with practical examples and troubleshooting tips.

Tutorials

If you are a website administrator and your server runs on Linux, you have probably encountered situations where you had to refer to the hosting control panel or even contact support to resolve a simple issue. But the truth is that mastering Linux commands not only multiplies your work speed, but also becomes your only lifeline in critical situations — such as DDoS attacks or disk full errors. In this article, we review 25 practical commands with real-world examples that every website administrator should know.

1. File and Directory Management

Working with files starts simple, but combining these commands correctly can drastically reduce your time.

ls and ll — Viewing Files

The ls command is the most basic tool, but with the right flags you can get more detailed information:

ls -lah /var/www/html

This command shows all files with human-readable sizes (like 4.2K) and modification dates. Add the -t option to list the newest files first: ls -lt.

find — Advanced Search

Suppose you have found a large log file that is filling up the disk:

find /var/log -type f -size +100M -exec ls -lh {} \;

This command lists all files larger than 100 megabytes in /var/log with their sizes. To delete files older than 30 days in a temporary directory:

find /tmp -type f -mtime +30 -delete

tar — Backup and Compression

To back up an entire website directory:

tar -czvf backup.tar.gz /var/www/html

And to extract it to a new destination:

tar -xzvf backup.tar.gz -C /home/user/restore

Common mistake: Forgetting the -C flag causes files to be extracted into the current directory and messes up the folder structure.

2. Process Management

When your website is slow, the first step is to check the running processes.

ps and top — Viewing Processes

To see all processes of a specific user:

ps -u www-data -o pid,%cpu,%mem,cmd

The top command provides a live view. But for a one-time output that can be scripted, use top -bn1. If you want to see only the top 5 resource-consuming processes:

top -bn1 | head -20 | tail -10

kill and killall — Terminating Processes

If a PHP-FPM process is stuck, first find its PID:

pgrep -f "php-fpm: pool"

Then terminate it with a soft signal (SIGTERM):

kill -15 12345

If it does not terminate, try the hard signal (SIGKILL):

kill -9 12345

Important note: Always start with -15 to give the process a chance to clean up. Overusing -9 can damage the database.

systemctl — Service Management

On modern distributions (Ubuntu 16.04+, CentOS 7+) for service management:

systemctl restart nginx
systemctl status mysql

To enable a service at boot:

systemctl enable --now redis-server

3. Network Management

Network issues are the most common cause of website downtime. Make sure you know these commands.

ss — Checking Ports and Connections

To see who is connected to port 80 (HTTP):

ss -tunap | grep :80

To count the number of active connections to port 443 (HTTPS):

ss -tn state established '( dport = :443 )' | wc -l

This command is very useful for detecting SYN flood attacks.

curl — HTTP Testing

To check server response headers:

curl -I https://example.com

To measure total response time:

curl -o /dev/null -s -w "time_total: %{time_total}s\n" https://example.com

If you want to see which IP the request was sent from:

curl -v https://example.com 2>&1 | grep "Connected"

ping and traceroute — Connection Troubleshooting

To test connectivity to a server:

ping -c 4 8.8.8.8

And to find the point of failure along the route:

traceroute -n example.com

Common mistake: If ping does not respond, do not immediately conclude that the server is down. Many servers filter ICMP. First test with curl or nc.

4. Disk and Filesystem Management

A full disk is one of the most common reasons for website downtime. These commands are your lifesavers.

df and du — Checking Disk Space

To see overall disk space:

df -h

To find the largest directories in the website root:

du -sh /var/www/html/* | sort -rh | head -10

This combined command shows the 10 largest folders sorted by size.

lsof — Open Files

If you have deleted a file but the disk is still full, a process is likely holding it in memory:

lsof +L1

This command shows deleted files that are still open. You can then stop the related process with kill.

rsync — Synchronization and Transfer

To transfer files between servers while preserving permissions:

rsync -avz --progress /var/www/html/ user@backup-server:/backup/html/

The -a (archive) flag preserves permissions and timestamps, -z compresses, and --progress shows progress.

5. User and Permission Management

Your server's security depends on proper user management.

useradd and usermod — User Management

To create a new user with a restricted shell:

useradd -m -s /bin/bash deploy

To add a user to the sudo group:

usermod -aG sudo deploy

Important note: Always use the -a (append) flag. Without it, the user will be removed from their previous groups.

chmod and chown — Permissions

To change ownership of website files to the web server user:

chown -R www-data:www-data /var/www/html

To set correct permissions for directories (755) and files (644):

find /var/www/html -type d -exec chmod 755 {} \;
find /var/www/html -type f -exec chmod 644 {} \;

6. Viewing Logs

Logs are the first place to look when errors occur.

tail and grep — Viewing and Filtering Logs

To follow the Nginx error log live:

tail -f /var/log/nginx/error.log

To find 500 errors within a time period:

grep " 500 " /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -rn

This command shows the IPs that have generated the most 500 errors along with their counts.

journalctl — systemd Logs

To see MySQL service logs from the beginning of today:

journalctl -u mysql --since today

To follow logs live:

journalctl -u nginx -f

7. Combined and Advanced Commands

These combined commands accomplish complex tasks in a single line.

grep and awk — Text Processing

To extract HTTP status codes from logs and count them:

awk '{print $9}' /var/log/nginx/access.log | sort | uniq -c | sort -rn

To find the slowest requests (based on response time):

awk '{if ($NF > 5) print $0}' /var/log/nginx/access.log | tail -20

watch — Periodic Execution

To view memory usage live every 2 seconds:

watch -n 2 free -h

To monitor network connections:

watch -n 1 'ss -s'

8. Troubleshooting and Common Mistakes

In this section, we highlight several frequent mistakes made by novice administrators.

Unnecessary Use of sudo

Always log in as a regular user and use sudo only for specific commands. Running commands as root can inadvertently damage system files.

Forgetting the -a Flag in usermod

As mentioned, without -a, the user is removed from their previous groups. This mistake can cut off the user's SSH access.

Ignoring Command Output

Before running destructive commands like rm or dd, always verify the output with ls or df. A typo in the path can cause a disaster.

Summary

Mastering these 25 Linux commands will help you resolve many common server issues without needing support. I recommend practicing these commands in a test environment (such as VirtualBox or a cheap VPS) so you can act confidently in real-world situations. If your server runs on cloud infrastructure, ServerNet provides full SSH access to your server, allowing you to practice these commands directly on it. Remember to study the documentation of each command with man — Linux itself is the best teacher.

ServerNet Support

ServerNet engineering & editorial team — specialists in infrastructure, networking and web hosting.

WordPress Hosting
Share:

Comments 0

No comments yet — be the first!

Leave a comment

Related service

WordPress Hosting

A purpose-built WordPress stack on LiteSpeed Enterprise and NVMe — auto-install, secure updates, staging and caching that keeps you on top of Google.