As a VPS (Virtual Private Server) administrator, mastering Linux commands is essential for managing, troubleshooting, and maintaining server performance. Linux servers are known for their efficiency, flexibility, and stability, but to unleash their full potential, you need to be familiar with the most useful commands. In this guide, we explore the top 10 Linux commands every VPS administrator should know.
1. ls
- List Directory Contents
The ls
command lists the contents of a directory. It’s one of the most basic yet powerful commands.
Usage:
ls
Common Options:
ls -l
: Displays detailed information about files and directories.
ls -a
: Shows hidden files (files starting with a dot).
ls -lh
: Displays file sizes in human-readable format.
2. cd
- Change Directory
Use the cd
command to navigate through the file system on your server.
Usage:
cd /path/to/directory
cd ..
: Move up one level in the directory structure.
cd ~
: Go to the home directory.
cd /
: Go to the root directory.
3. top
- Monitor System Processes
The top
command provides a real-time view of system processes, CPU, and memory usage.
Usage:
top
Key Features:
- Monitor resource usage for each process.
- Kill unresponsive processes (press
k
and enter the process ID).
- Sort processes by CPU or memory usage (press
M
or P
).
4. df
- Disk Space Usage
The df
command displays the available and used disk space for all mounted file systems.
Usage:
df -h
The -h
flag shows the output in a human-readable format (GB, MB, etc.).
5. du
- File and Directory Size
Use the du
command to check the size of files and directories.
Usage:
du -sh /path/to/directory
-s
: Summarize the total size.
-h
: Display sizes in human-readable format.
6. grep
- Search for Text in Files
The grep
command allows you to search for specific text patterns within files.
Usage:
grep "search_term" filename
Example: Search for the word “error” in a log file:
grep "error" /var/log/syslog
7. chmod
- Modify File Permissions
Use the chmod
command to change file or directory permissions.
Usage:
chmod 644 filename
Common permission levels:
644
: Read and write for the owner, read-only for everyone else.
755
: Read, write, and execute for the owner; read and execute for others.
8. systemctl
- Manage System Services
The systemctl
command is essential for managing system services on systems running systemd.
Usage:
systemctl status service-name
: Check the status of a service.
systemctl start service-name
: Start a service.
systemctl stop service-name
: Stop a service.
systemctl restart service-name
: Restart a service.
9. tail
- View End of a File
The tail
command displays the last few lines of a file, which is useful for monitoring log files.
Usage:
tail -n 50 /var/log/syslog
Use tail -f
to follow live updates in a file:
tail -f /var/log/syslog
10. reboot
and shutdown
- Restart or Power Off Server
Reboot or shut down your VPS server safely with these commands:
sudo reboot
: Reboots the server.
sudo shutdown -h now
: Powers off the server immediately.
sudo shutdown -r now
: Restarts the server.
Conclusion
Mastering these essential Linux commands is critical for managing and troubleshooting your VPS server efficiently. Whether you are monitoring processes, managing disk space, or restarting services, these commands will empower you to keep your server running smoothly and securely.