HomeProjectsBlogContact

Linux Command Line Basics Every Web Developer Needs

Servers, containers and CI all speak Linux. The commands you'll actually use for files, searching, processes, logs, permissions and networking, plus pipes that turn small tools into superpowers.

Linux Command Line Basics Every Web Developer Needs

Even if you develop on Windows or macOS, your code almost certainly runs on Linux: in a container, on a VPS, inside a CI runner. Sooner or later you'll SSH into a server at an awkward moment with something broken. Knowing a few dozen commands turns that from panic into a short checklist.

Moving around

pwd                 # where am I?
ls -la              # list files, including hidden ones, with details
cd /var/www/app     # change directory
cd ..               # up one level
cd ~                # home directory
cd -                # back to the previous directory

Use Tab to autocomplete paths. It saves time and typos.

Working with files

mkdir -p logs/archive     # create nested directories
touch notes.txt           # create an empty file
cp config.example config  # copy
mv old.txt new.txt        # move or rename
rm file.txt               # delete (no recycle bin!)
rm -r folder/             # delete a directory and its contents

rm is permanent. Double-check paths, especially with -r and anything involving *.

Reading files

cat package.json          # print the whole file
less app.log              # scroll through big files (q to quit, / to search)
head -n 20 app.log        # first 20 lines
tail -n 50 app.log        # last 50 lines
tail -f app.log           # follow new lines as they're written

tail -f on a log file while reproducing a bug is one of the most useful debugging moves on a server.

Searching

grep "ERROR" app.log                 # lines containing ERROR
grep -i "timeout" app.log            # case-insensitive
grep -rn "DATABASE_URL" .            # recursive, with line numbers
find . -name "*.log" -mtime +7       # .log files older than 7 days

Pipes: combining small tools

The | symbol sends one command's output into another. This is where the command line gets powerful:

# How many errors today?
grep "ERROR" app.log | wc -l

# Top 10 IP addresses hitting the server
awk '{print $1}' access.log | sort | uniq -c | sort -rn | head

# Find the process using the most memory
ps aux --sort=-%mem | head -5

Redirection saves output to files: > overwrites, >> appends, and 2>&1 includes errors.

Permissions

ls -l deploy.sh            # -rwxr-xr-x  owner/group/others permissions
chmod +x deploy.sh         # make executable
chmod 600 ~/.ssh/id_ed25519  # owner read/write only (required for SSH keys)
chown www-data:www-data uploads/   # change owner
sudo command               # run as administrator

"Permission denied" is usually one of three things: the file isn't executable, the wrong user owns it, or you need sudo. Avoid chmod 777; it gives everyone full access and is almost never the right fix.

Processes

ps aux | grep node        # find running Node processes
top                       # live view of CPU and memory (htop is nicer if installed)
kill 12345                # ask a process to stop
kill -9 12345             # force it (last resort)

"Port already in use"? Find what's holding it:

sudo lsof -i :3000
# or
sudo ss -ltnp | grep 3000

Disk space

A full disk causes bizarre errors: failed writes, crashed databases, broken deploys.

df -h                     # free space per disk
du -sh *                  # size of each item in the current directory
du -sh /var/log/*         # find which logs are huge

Old logs, Docker images and build artefacts are the usual culprits. (docker system prune cleans unused Docker data, but read the prompt first.)

Services and logs

Most Linux servers use systemd to run long-lived services:

sudo systemctl status nginx       # is it running?
sudo systemctl restart myapp      # restart a service
sudo systemctl enable myapp       # start on boot
journalctl -u myapp -f            # follow a service's logs
journalctl -u myapp --since "1 hour ago"

Networking

curl -I https://example.com        # response headers only
curl -s localhost:3000/health      # is the app answering locally?
ping example.com                   # basic reachability
dig example.com +short             # DNS lookup
ss -ltnp                           # which ports are listening

Testing localhost from the server itself quickly tells you whether a problem is the app or something in front of it, like Nginx, a firewall or DNS. (DNS explained.)

Remote access

ssh deploy@203.0.113.10                 # log in
scp backup.dump deploy@server:/tmp/     # copy a file to the server

Use SSH keys, not passwords. (SSH keys explained.)

Habits that save you

  • Use history and Ctrl+R to search previous commands.
  • Read before you run. Especially commands copied from the internet that use sudo, rm -rf or curl ... | bash.
  • Check man command or command --help for options.
  • Keep notes of commands that solved real problems. That file becomes your personal runbook.

Ready to use these for real? Try deploying a Node.js app to a VPS.

FAQ

What Linux commands should a web developer know?

Navigation (cd, ls), file operations (cp, mv, rm), reading files (cat, less, tail -f), searching (grep, find), permissions (chmod, chown), processes (ps, kill), disk usage (df, du), services (systemctl, journalctl) and networking (curl, ss, ssh).

How do I find what's using a port on Linux?

Run sudo lsof -i :PORT or sudo ss -ltnp | grep PORT to see which process is listening on that port.

Can I learn Linux commands on Windows?

Yes. Use WSL (Windows Subsystem for Linux) to run a real Linux environment, or Git Bash for many common commands.

Keep reading

More from the workbench

All articles →