Table of Contents
- Start with the four commands that solve most problems
- Navigating and reading files without a control panel
- Searching logs and files with grep
- Checking disk space, memory and what is eating the server
- Moving, copying and cleaning up files safely
- When the terminal is the wrong tool
- A short procedure for diagnosing a broken site
- Frequently asked questions[+]
The commands that matter most to a site owner answer three questions fast. What is on this server, what is filling the disk, and what does the error log say? Once you can list files, search text, check space and read permissions, most hosting emergencies turn into a five-minute job instead of a support ticket.
This guide explains the Linux terminal commands worth memorising for someone who runs a website and not a data centre. These commands are commonly used through an SSH terminal on a Linux server.
Start with the four commands that solve most problems
You do not need a hundred commands. You need four, used well.
The first is ls, which lists what is in a directory. The second is cd, which moves you between directories. The third is grep, which searches text inside files. The fourth is df, which tells you how full the disk is. Between them, these four answer the questions that wake people up at night.
Get comfortable with ls first. It is a commonly used command, and its manual documents many options. By default, ls reports file system usage in 1024-byte blocks. That is why the numbers in the size column can look odd until you learn to read them. Add the --si flag and it switches to powers of 1000 instead.
A few
lsvariations earn their place in muscle memory:
ls -lashows hidden files and permissions, including the.htaccessfile you may be hunting for.ls -lhprints sizes in human-readable units.ls -ltsorts by modification time, newest first, which is how you spot a file that changed when it should not have.ls -Rwalks subdirectories, useful on a small site and noisy on a large one.
One detail is worth knowing. ls assumes tab stops every 8 columns when it formats output, unless you tell it otherwise. That only matters if you are piping output somewhere tidy, but it explains the occasional strange spacing.

Navigating and reading files without a control panel
The control panel shows you a folder tree. The terminal shows you the same tree faster, and it never times out halfway through loading.
cd .. goes up one level. cd ~ returns you home. pwd prints where you are, which sounds trivial until you have been lost in a directory structure for ten minutes.
To read a file, cat filename dumps the whole thing to the screen. For anything longer than a screenful, use less filename, which lets you scroll and search with the / key. For the last few lines of a log, tail -f error.log follows the file live as new lines arrive. That single command is the fastest way to watch what happens when you load a broken page.
head shows the top of a file and tail shows the bottom. Both accept a number, so tail -50 access.log gives you the last fifty lines. On a busy site those fifty lines tell you more about a problem than an hour of guessing.
ls -l prints permission information such as -rw-r--r-- next to each file. The first group is the owner, the second the group, the third everyone else. r is read, w is write, x is execute. If a PHP file is readable by the web server, it will run. If a directory is not executable, nothing inside it can be opened at all.
chmod changes those letters.
chown changes who owns a file. This is the command that fixes the classic “the upload worked but the site cannot read it” problem after you move files with a tool that runs as a different user.
Searching logs and files with grep
When something breaks, a log file can help, and grep is how you search it.
grep "error" error.log prints every line containing that word. grep -i ignores case, so it catches Error and ERROR too. grep -r "search term" /var/www/html searches every file under a directory recursively, which is how you find which template is emitting a stray piece of text.
Two flags are worth remembering for triage. grep -n prefixes each matching line with its 1-based line number, so you can jump straight to it in an editor. grep -b prints the 0-based byte offset instead. This matters when you are dealing with binary files or building a script around the output.
grep -c counts matches rather than printing them. That is how you answer “how many times did this happen today” without scrolling. grep -v inverts the match and shows everything that does not contain the pattern, which is handy for filtering noise out of a log.
One quirk is worth knowing. Where an option takes a count, a value of -1 is treated as infinity, so grep does not stop. That is useful when you want every match and do not know how many there are.
For anything involving file transfer, the same terminal habits apply. If you are unsure what the protocol is called, this explanation of what FTP stands for in plain English covers the basics before you go looking for a client.

Checking disk space, memory and what is eating the server
A full disk can stop uploads, sessions and database writes. The terminal reports filesystem usage in one line.
df -h shows every mounted filesystem and how full it is, in human-readable units. Run df -h before you run anything else when a site goes strange.
du -sh /var/www/html tells you how big a directory is. du -h --max-depth=1 /var breaks that down one level, which is how you find the folder that grew without anyone noticing. Old backups and rotated logs are the usual suspects.
free -h shows memory and swap.
top shows what is running and what is using the processor. Press q to leave. htop is an alternative if it is installed.
ps aux lists running processes. Pipe it through grep to find one specific thing. ps aux | grep php shows every PHP process. If you see dozens of them and the site is idle, something is stuck.
kill stops a process by its ID. Start with a plain kill and only escalate if the process refuses to go. If you are comparing transfer methods, this comparison of plain FTP versus FTPS versus SFTP explains which one protects what. Killing the wrong process on a live server is a fast way to learn why you check the ID twice.
Moving, copying and cleaning up files safely
cp copies, mv moves, rm deletes. The first two are forgiving. The third is not.
rm does not use a recycle bin. There is no undo. Before you delete anything, run ls on the exact path and read the output. A stray space in an rm -rf command can delete an unintended path.
cp -r source destination copies a directory and everything inside it. mv oldname newname renames a file, and it also moves files between directories. Neither asks for confirmation, so slow down on production.
mkdir creates a directory. touch creates an empty file or updates a timestamp. find locates files by name, size or age.
tar -czf backup.tar.gz /var/www/html creates a compressed archive. tar -xzf backup.tar.gz unpacks it. Use them to take a snapshot before a risky change.
On the subject of hosting, not every site needs a paid server to practise these commands. This InfinityFree review of what free hosting really costs you discusses those trade-offs.
When the terminal is the wrong tool
The terminal is fast, precise and unforgiving. It is the wrong choice in a few situations, and knowing them saves you a bad afternoon.
If you are not sure which file you are editing, stop. Use the control panel or download the file first. A mistaken
mvon a live site takes the page down instantly, and the fix requires knowing exactly what the file was called before you touched it.
If the task involves credentials, be careful what you type where. Commands land in shell history, and history is readable by anyone who gets the right access.
If the server is managed by your host and you do not have root, some commands will simply refuse. That is not a failure on your part. Ask the host which commands are permitted before you build a workflow around one.
And if a command needs a flag you have never used, read the manual. man ls and man grep are installed on the server and are always more accurate than a forum post from years ago. Press q to exit the manual.

A short procedure for diagnosing a broken site
When a site goes down and you have terminal access, work in this order.
- Run
df -hand check that no filesystem is full. - Run
free -hand check that memory and swap are not exhausted. - Run
tail -50on the error log to see the most recent failures. - Run
grep -i erroron the same log to catch anything the last fifty lines missed. - Run
ls -laon the web root and confirm the files are where they should be and readable. - Run
ps aux | grepfor your web server or PHP process and confirm it is running. - Only then start changing things, and take a
tarbackup before the first change.
Run the checks in that order before changing files.
Frequently asked questions
Do I need to know Linux to run a website?
No. A managed host gives you a control panel and handles the server for you. Terminal skills become valuable when you want to diagnose problems yourself, move files quickly or work on a server you rent directly.
What is the difference between ls and ls -l?
ls prints names only. ls -l prints a long listing with permissions, owner, group, size and modification date for each file, which is what you need when a file will not load.
Why does my disk show full when I deleted large files?
A process may still be holding a deleted file open, so the space is not released until that process restarts. Check with df -h, find the process with lsof if it is installed, and restart the service.
Is it safe to use rm on a live server?
Only when you have checked the exact path with ls first. rm has no recycle bin and no undo, so a wrong path deletes production files permanently. Take a tar backup before any cleanup.
What does grep -r do?
It searches recursively through every file in a directory and its subdirectories. That makes it the fastest way to find which template or config file contains a specific string.
Thank you for reading!

