Web development · 5 min read

A Practical Guide to Common Bash Commands for Server Management and Web Development

If you build or maintain websites, you will spend time in a terminal. This practical toolkit covers the everyday Bash commands that keep a server and a deploy running.

Bash is the default shell on most Linux servers, and a small set of commands covers most daily work: moving around the filesystem, checking a process, shipping a deploy, or reading a log when a site misbehaves. Each command below includes a short explanation and an example you can adapt.

Navigation and files

pwd prints the current directory, which helps after you have jumped between project, backup, and system paths.

pwd

cd changes directory. Use - to return to the previous path, and ~ for your home directory.

cd /var/www/mysite
cd -

ls lists files. These flags show hidden files, permissions, owners, and human-readable sizes.

ls -lah

mkdir -p creates a directory and any missing parent folders in one step.

mkdir -p /var/www/mysite/storage/logs

cp copies files. -r copies a directory recursively. mv renames or moves a file or folder.

cp -r /var/www/mysite /var/backups/mysite-copy
mv draft.env .env

cat prints a file. For longer files, less lets you scroll and search without flooding the screen. Press q to quit.

cat /etc/nginx/sites-available/mysite
less /var/log/nginx/error.log

Permissions and ownership

Web servers often fail when a file has the wrong owner or permissions.

ls -l shows permissions, owner, and group.

ls -l /var/www/mysite

chmod changes permissions. 755 is common for directories and scripts: the owner can read, write, and enter or execute; others can read and enter or execute. 644 is common for ordinary files: the owner can edit, and others can only read.

chmod 755 deploy.sh
chmod 644 index.html

chown changes owner and group. On Ubuntu and Debian, the web server often runs as www-data. -R applies the change to a directory and its contents.

sudo chown -R www-data:www-data /var/www/mysite/storage

Avoid chmod 777. It makes a path world-writable and is almost never the right fix.

Processes and system resources

When a site is slow or a deploy appears stuck, check the machine before you change application code.

ps lists processes. Pipe it to grep to find one service.

ps aux | grep nginx

top shows a live view of CPU and memory use. Press q to quit.

top

kill asks a process to exit. Use the PID from ps or top. The default signal is SIGTERM (-15), which lets the program clean up. kill -9 sends SIGKILL and should be a last resort, because the process cannot shut down gracefully.

kill 2148
kill -9 2148

df -h reports disk space in a readable form. free -h shows memory, including swap.

df -h
free -h

Networking and remote work

Most server work happens over SSH.

ssh opens a remote shell. Add -p if the server does not use the default port 22.

ssh deploy@203.0.113.10
ssh -p 2222 deploy@203.0.113.10

scp copies files over SSH. -r copies a directory.

scp -r dist deploy@203.0.113.10:/var/www/mysite/

rsync is usually better for deploys and backups, because it copies only what changed. -a preserves permissions and timestamps, -v is verbose, and -z compresses data in transit. A trailing slash on the source matters: public/ copies the contents, not the folder itself. --dry-run previews the transfer without writing files.

rsync -avz --dry-run ./public/ deploy@203.0.113.10:/var/www/mysite/public/
rsync -avz ./public/ deploy@203.0.113.10:/var/www/mysite/public/

curl makes HTTP requests. -I fetches headers only, useful for checking a status code or redirect. -o saves the body to a file.

curl -I https://example.com
curl -o page.html https://example.com

Logs and searching

When something breaks, logs are usually faster than guesswork.

tail -f follows a file as new lines arrive. -n sets how much history to show first.

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

grep searches for a pattern. -i ignores case, -r walks a directory, and -n prints line numbers.

grep -i "error" /var/log/nginx/error.log
grep -rn "TODO" /var/www/mysite

journalctl reads systemd logs. -u selects a service, -f follows new entries, -n limits the line count, and --since limits the time window.

journalctl -u nginx -n 100 --since "1 hour ago"
journalctl -u nginx -f

Package and service management

On Debian and Ubuntu, apt installs software and systemctl controls services. Update the package index before you install anything.

sudo apt update
sudo apt install nginx

systemctl status shows whether a service is running and prints recent log lines. reload picks up a new configuration without a full restart when the service supports it, which is often preferable for Nginx. restart stops and starts it. enable makes it start on boot.

systemctl status nginx
sudo systemctl reload nginx
sudo systemctl restart nginx
sudo systemctl enable nginx

If a restart fails, check journalctl -u nginx before you change more settings.

Web development helpers

These commands show up constantly in deploys and project work.

git is how most teams move code. status shows what changed, pull fetches and merges from the remote, and log --oneline gives a compact history. Run git status on a server before you pull, so you do not overwrite uncommitted fixes.

git status
git pull
git log --oneline -n 10

find locates files by name, type, or age. -mtime +30 means last modified more than 30 days ago.

find /var/www/mysite -name "*.log"
find /var/www/mysite -type f -mtime +30

tar packs and unpacks archives. -c creates, -x extracts, -z uses gzip, -v is verbose, and -f names the file. Put the archive name immediately after -f.

tar -czvf mysite-backup.tar.gz /var/www/mysite
tar -xzvf mysite-backup.tar.gz

After a deploy, set permissions deliberately. This pattern makes directories enterable (755) and ordinary files readable but not executable (644). Then add execute permission only on scripts that need it.

find /var/www/mysite -type d -exec chmod 755 {} \;
find /var/www/mysite -type f -exec chmod 644 {} \;
chmod u+x /var/www/mysite/deploy.sh

Safety tips

A terminal does exactly what you type, including mistakes.

Be careful with rm -rf. It deletes recursively and without confirmation, and there is no undo. Never run it against /, against a path you have not checked with pwd and ls, or against a variable that might be empty. If $DIR is unset, rm -rf "$DIR/" can expand into a path you did not intend. Prefer a specific, fully written path, and consider moving a directory aside with mv before you delete anything on production.

Treat sudo as a multiplier. It can edit system files, restart services, and destroy data. Read the full command before you enter your password. If you use a shared deploy account, confirm you are on the right server with hostname and pwd.

Other habits that help: run rsync --dry-run before a real sync, avoid chmod 777 and chmod -R 777, quote your variables, and do not paste a long command into production until you understand every flag.

Conclusion

You do not need hundreds of commands to manage a server well. You need a reliable handful for the filesystem, permissions, processes, SSH, logs, and deploys. Practice them on a development machine or a disposable VPS, then use them the same way in production: look first, change second, and keep a backup you can restore.

At Tenshi Systems Engineering, we build websites and software, and these are the kinds of commands we use when we ship, debug, and keep a site healthy after launch.

All posts

Let's talk about your project

Tell us what you need. The consultation form takes about a minute.

Deploy Your Future