Featured image of post Essential Linux Commands and Pipes for Web Developers Featured image of post Essential Linux Commands and Pipes for Web Developers

Essential Linux Commands and Pipes for Web Developers

Master basic Linux shell commands and pipelines to search logs (grep/find), inspect server resources (htop/df), and automate terminal tasks.

Introduction

Whether you work on the frontend or backend, shell command proficiency is an important skill for web developers.

Command-line tasks arise constantly: sshing into AWS/VPS instances, debugging inside Docker containers, or writing automated CI/CD pipeline shell scripts (such as GitHub Actions).

This article covers essential Linux commands and explains how to chain them together using pipelines (|) to troubleshoot server issues and parse log files.


1. Searching Files and Parsing Logs

When a server crashes or behaves erratically, you must be able to search through massive text files quickly to locate the error.

Searches file contents for lines matching a specified string or pattern.

# Search for the word "fatal" in error.log, ignoring case distinctions (-i)
grep -i "fatal" /var/log/nginx/error.log

# Search recursively (-r) for the string "API_KEY" in the current directory
grep -r "API_KEY" ./src/

② find (Locating Files)

Finds files and directories based on file names, file sizes, or edit dates.

# Find all PNG images under the current directory
find . -name "*.png"

# Locate files modified within the last 24 hours
find . -mtime -1

2. Inspecting Server Resources and Processes

When a server is slow or experiencing memory leaks, these commands help diagnose the issue:

① top / htop (Real-Time Process Monitoring)

Lists running system processes alongside active CPU core loads and memory metrics.

  • htop is a popular alternative to top, featuring a color-coded, interactive terminal interface.

② df / du (Disk Space Usage)

Checks disk storage limits.

# Check overall disk usage in human-readable (-h) sizes (MB/GB)
df -h

# Check the total size of a specific directory (e.g., node_modules)
du -sh ./node_modules/

③ lsof / netstat (Network Port Monitoring)

If you get an “Address already in use” error when starting a local server, use this to find the process occupying the port:

# List the Process ID (PID) occupying port 3000
lsof -i :3000

3. Combining Commands with Pipes (|) and Redirects

The power of the Linux CLI lies in pipelines (|), which feed the output (stdout) of one command directly into the input (stdin) of another.

Example A: Aggregating Unique IP Addresses from access.log

Extract, sort, and display the top 10 unique IP addresses hitting your server:

# Read the log, extract the IP column, count duplicates, and sort in descending order
cat access.log | awk '{print $1}' | sort | uniq -c | sort -nr | head -n 10
  • awk '{print $1}': Extracts only the first space-delimited column (the client IP address).
  • sort: Sorts the lines (required by uniq).
  • uniq -c: Dedupes identical consecutive lines and prefixes each line with its frequency count.
  • sort -nr: Sorts the output numerically (-n) in reverse (-r - descending) order.
  • head -n 10: Limits the output to the top 10 results.

Example B: Force-killing a Port-blocking Process

If a local server crashes without releasing its port, find and terminate the process in one line:

# Find the PID for port 3000 and pass it directly to the kill command
kill -9 $(lsof -t -i :3000)

Conclusion

Using CLI commands is faster and more efficient than navigating GUI menus or opening log files manually.

  1. Use grep and find to locate errors and files in seconds.
  2. Use htop, df, and lsof to troubleshoot system resources.
  3. Chain commands using pipelines (|) to parse data.

Practicing in the terminal will improve your daily workflow and infrastructure operations.