Git & Linux LinuxTerminalDevOps

Essential Linux Commands Every Developer Must Know

Why Every Developer Needs Linux Skills

Linux powers the vast majority of the world's web servers, cloud infrastructure, containers, and embedded systems. The moment you deploy a web application, you are almost certainly deploying it to a Linux server. Developers who are fluent at the Linux command line can SSH into a production server, diagnose and fix issues in real time, analyse log files, manage running services, and automate deployments — tasks that graphical tools simply cannot handle remotely or with the same precision.

Beyond deployments, Linux concepts underpin how every modern application actually works. File permissions, environment variables, stdin/stdout pipes, processes, and signals are the plumbing beneath every program you write, regardless of language. Understanding Linux makes you a significantly better programmer, not just a better system administrator.

Navigating the Filesystem

pwd                   # print working directory — where am I right now?
ls                    # list contents of current directory
ls -la                # long format + hidden files (starting with .)
ls -lh                # human-readable file sizes (KB, MB, GB)
ls -lt                # sort by modification time (newest first)

cd /var/log           # jump to an absolute path
cd projects/webapp    # change to a relative path
cd ..                 # go up one directory level
cd ~                  # go to your home directory (/home/username)
cd -                  # go back to previous directory (very handy!)

File and Directory Management

# Creating files and directories
touch config.json             # create empty file (or update timestamp)
mkdir dist                    # create a directory
mkdir -p src/components/ui    # create nested directories in one command

# Copying files and directories
cp package.json package.json.backup      # copy a file
cp -r src/ src_backup/                   # copy entire directory (-r = recursive)

# Moving and renaming
mv old-name.py new-name.py               # rename a file
mv ./temp_files/ ~/projects/archive/     # move a directory

# Removing (be extremely careful — there is no Recycle Bin!)
rm unused.log                 # delete a file permanently
rm -rf node_modules/          # delete a directory recursively (DANGEROUS)
rmdir empty_directory/        # delete an empty directory (safer alternative)

Viewing and Searching File Contents

cat server.log                # print entire file to the terminal
less server.log               # scrollable view (press q to quit, / to search)
head -n 20 server.log         # show only the first 20 lines
tail -n 50 server.log         # show only the last 50 lines
tail -f app.log               # follow a log file in REAL TIME (Ctrl+C to stop)

# Searching within files — grep is incredibly powerful
grep "ERROR" app.log                   # lines containing "ERROR"
grep -i "warning" app.log             # case-insensitive search
grep -r "TODO" ./src/                  # recursive search across a folder
grep -n "function" utils.js            # show matching line numbers
grep -v "DEBUG" app.log               # lines that do NOT match

# Finding files by name or properties
find . -name "*.py"                    # all Python files in current tree
find /var/log -name "*.log" -mtime -7 # log files modified in last 7 days
find . -size +10M                      # files larger than 10 megabytes

File Permissions

Every file and directory in Linux has permissions assigned to three groups: the owner (the user who created it), the group (a shared group of users), and others (everyone else). Each group can have read (4), write (2), and execute (1) permissions. You can combine these: 7 = rwx (full), 6 = rw-, 5 = r-x, 4 = r--.

ls -l deploy.sh
# Output: -rwxr-x--- 1 alice devteam 2341 Apr 15 deploy.sh
#          |||   |||   |||
#          |||   |||   └── others: --- (no permissions = 0)
#          |||   └─────── group:  r-x (read + execute = 5)
#          └──────────── owner:  rwx (read + write + execute = 7)

chmod 755 deploy.sh       # owner everything, group + others read+execute
chmod 644 index.html      # owner read+write, everyone else read-only
chmod 600 .env            # owner read+write ONLY — keep secrets safe!
chmod +x build.sh         # add execute permission for all groups

chown alice script.sh              # change owner to 'alice'
chown alice:devteam script.sh      # change owner AND group

Process Management

ps aux                         # list every running process with details
top                            # live process monitor (press q to quit)
htop                           # better interactive monitor (if installed)

# Killing processes
kill 1234                      # send SIGTERM to process ID 1234 (graceful stop)
kill -9 1234                   # force kill with SIGKILL (last resort)
pkill -f "python server.py"    # kill processes matching a name pattern

# Background processes
python server.py &             # run in background (& at the end)
nohup python server.py &       # keep running even after terminal closes
jobs                           # list current background jobs
fg %1                          # bring background job 1 to foreground
Ctrl + Z                       # pause current foreground process

Pipes and Redirection — The Power of Combining Commands

The pipe operator (|) is the most powerful concept in the Linux shell. It connects the output of one command to the input of another, letting you build complex processing pipelines from simple building blocks:

grep "ERROR" app.log | wc -l                   # count error lines
grep "ERROR" app.log | sort | uniq -c          # count unique error types

ls -la | sort -k5 -rn | head -20               # 20 largest files

# Redirection
ls -la > file_list.txt                          # write output to file (overwrite)
echo "Deploy completed $(date)" >> deploy.log   # append to file
command 2>/dev/null                             # discard error messages
command > output.txt 2>&1                       # redirect both stdout+stderr

# Command chaining
git pull && npm install && npm run build        # run only if previous succeeds
git pull || echo "Pull failed!"                # run only if previous FAILS

Environment Variables and the Shell Profile

printenv                        # list all environment variables
echo $HOME                      # view a specific variable
echo $PATH                      # show the command search path

# Set for current session only
export DATABASE_URL="postgresql://localhost/myapp"
export PORT=3000

# Permanently add to ~/.bashrc or ~/.zshrc:
echo 'export API_KEY="your_secret_key"' >> ~/.bashrc
source ~/.bashrc                # reload the profile immediately
← Back to Blog 📚 Browse Courses