Article VPS & Servers

The Linux commands you will actually use

The commands that come up constantly on a real VPS, grouped by what you are actually trying to do rather than listed alphabetically.

Updated 10 min read Beginner

Running a VPS well does not require memorising hundreds of commands — a genuinely small, repeated set covers the vast majority of what you actually do, day to day. This is that set, grouped by task rather than dumped alphabetically, so it doubles as a reference you can come back to.

Finding your way around

pwd                 # print the current directory
ls -la               # list files, including hidden ones, with detail
cd /var/www          # change directory
cd ~                 # go to your home directory
cd -                 # go back to the previous directory

ls -la specifically is worth defaulting to over a plain ls — the -a shows hidden files (anything starting with a dot, including configuration files most tools rely on), and -l shows permissions, ownership and size, which you need constantly once you start troubleshooting.

Working with files and directories

cp file.txt backup.txt         # copy a file
cp -r directory/ backup/       # copy a directory recursively
mv oldname.txt newname.txt     # rename or move a file
rm file.txt                    # delete a file
rm -r directory/               # delete a directory and its contents
mkdir newfolder                # create a directory
touch file.txt                 # create an empty file, or update its timestamp
There is no undo for rm

Deleted files do not go to a recycle bin on a server — they are simply gone. Before running rm -r on anything, run ls on the same path first to confirm exactly what you are about to delete, and never run rm -rf with a path built from a variable you have not double-checked is set correctly.

Reading files

cat file.txt              # print the whole file
less file.txt              # scroll through a long file; q to quit
head -20 file.txt          # first 20 lines
tail -20 file.txt          # last 20 lines
tail -f file.txt           # follow a file live as it grows — ideal for logs

Permissions and ownership

chmod 644 file.txt          # owner: read/write, everyone else: read only
chmod 755 script.sh         # owner: full, everyone else: read and execute
chown yourname:yourname file.txt   # change the owning user and group

The three chmod digits are user, group, and everyone else, each a sum of read (4), write (2) and execute (1). 644 is the standard permission for a normal file; 755 is standard for a directory or an executable script. Add -R to either command to apply it recursively through a directory.

Searching

grep "error" logfile.txt              # find lines containing "error"
grep -ri "error" /var/log/            # case-insensitive, recursive through a directory
find /var/www -name "*.php"           # find files by name pattern
find /var/log -mtime +30 -name "*.log"  # files older than 30 days

grep searches inside file contents; find searches for files by name, age, size or type. They are commonly chained together — find a set of files, then search inside them — but each solves a different half of "where is this".

Processes

ps aux                    # list every running process
ps aux | grep nginx       # narrow it down to processes matching "nginx"
top                       # live view, sorted by CPU usage
kill PID                  # ask a process to stop
kill -9 PID               # force it, if it will not stop cleanly

See seeing what is using your server resources for a fuller treatment of diagnosing resource usage, and screen and tmux for keeping a long-running process alive after you disconnect.

Services

sudo systemctl status nginx     # is it running?
sudo systemctl restart nginx    # stop and start it
sudo systemctl enable nginx     # start automatically on boot
journalctl -u nginx -f          # follow its logs live

Networking

ip a                     # list network interfaces and their IP addresses
ss -tulpn                # list listening ports and the process using each
ping example.com         # check basic connectivity and latency
curl -I https://example.com   # fetch just the HTTP headers of a URL
dig example.com           # query DNS directly

Disk and memory

df -h                     # disk space, human-readable
du -sh directory/         # size of a specific directory
free -h                   # memory usage, human-readable

Getting root, and getting back out of it

sudo command               # run one command as root
sudo -i                    # start a full root shell
exit                       # leave a root shell, or close the terminal

Prefer sudo command for a single action over sudo -i for an extended session — it keeps a clearer record of exactly what was run with elevated privileges, and it is much harder to run something destructive by accident when every privileged command is deliberate rather than typed inside an already-root shell.

Piping and redirecting output

command1 | command2         # send command1's output into command2
command > file.txt          # write output to a file, overwriting it
command >> file.txt         # append output to a file
command 2>&1                # merge error output with normal output

The pipe (|) is what makes the commands above genuinely composable — ps aux | grep nginx is two simple commands combined into one useful answer, and the same pattern (list everything, then filter it) recurs constantly once you start combining these tools rather than using each in isolation.

Building the habit

None of this needs memorising in one sitting. The realistic path is using these repeatedly on your own server until the common ones — cd, ls, sudo systemctl status, tail -f, grep — stop requiring conscious thought, at which point troubleshooting a VPS stops feeling like a foreign skill and starts feeling like the same half-dozen tools applied to a slightly different problem each time.

Related reading