iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

Intro

Linux + Bash is the lingua franca of servers. The shell is your remote-control: navigate, glue tools, write small programs.

Linux + Bash — what it is

EXAMPLE
# ===== The pieces =====
# Linux:  open-source Unix-like OS (kernel + GNU userland)
# Shell:  Bash by default on most distros; zsh on macOS
# Tools:  small programs that read stdin, write stdout, exit with a code

# ===== Hello, shell =====
echo 'hello'
pwd                              # where am I?
ls -la                           # list files (long, all)
cd projects/shop && ls

# ===== Filesystem basics =====
mkdir -p data/logs
cp file.txt backup/
mv file.txt notes.txt
rm -rf old/                      # careful: -rf is destructive

# ===== Pipelines =====
cat access.log | grep '/login' | wc -l
ps aux | sort -k 3 -rn | head -5
# stdin -> filter -> filter -> output

# ===== Redirection =====
command > out.txt                # stdout to file (truncate)
command >> out.txt               # append
command 2> err.txt               # stderr to file
command > out.txt 2>&1           # both
command < in.txt                 # stdin from file

# ===== Variables + quoting =====
name='Alex'
echo "Hi $name"                 # double quotes interpolate
echo 'Hi $name'                  # single quotes do NOT

# ===== Loops + conditionals =====
for f in *.log; do
  echo "=== $f ==="
  head -3 "$f"
done

if [ -f /etc/passwd ]; then
  echo 'exists'
else
  echo 'missing'
fi

# ===== Permissions =====
chmod 755 script.sh              # rwx for owner, rx for others
chmod +x script.sh
chown user:group file
sudo command                     # run as root

# ===== Processes =====
ps aux | grep node               # find running processes
top                              # live process list
htop                             # nicer top (often need to install)
kill -9 12345                    # SIGKILL pid 12345

# ===== Where to be careful =====
# - rm -rf /  -- destroys everything you have access to
# - dd if=... of=/dev/sda  -- wipes a disk
# - chmod 777 -- world-writable, almost always wrong
# - sudo curl url | sh  -- audit anything before piping to a shell

# ===== When Linux + Bash wins =====
# - Servers, containers, CI runners
# - Quick text processing / log forensics
# - Cron jobs and tiny services

# ===== When Bash hurts =====
# - Anything > 100 lines (move to Python / Go)
# - Complex JSON manipulation (use jq + a real language)
# - Cross-platform tools (Powershell on Windows, Bash on Unix)

# ===== Patterns to internalise =====
# - Read stdin, write stdout, return a non-zero code on failure
# - Quote everything (set -u shows you what's missing)
# - set -euo pipefail at the top of scripts
# - One tool, one job; compose with pipes

# ===== Pitfalls =====
# - Forgetting to quote $variables -> word splitting bugs
# - cd somewhere then forgetting -> later commands run in wrong dir
# - Naming a script test (shadows Bash's [ ] / test builtin)
# - Using echo for binary data -> use printf / cat

Why it matters

Linux + Bash is the bedrock layer. Get comfortable with navigation, pipes, redirection, and a few core tools (grep, awk, sed, sort, uniq, find), and you can drive servers, containers, and CI without leaving the terminal. Keep scripts short; promote anything ambitious to a real language.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
# Linux is a kernel. "Linux" colloquially means kernel + GNU userland.
uname -a
Try it Yourself »

Exercise

Print the running kernel release.

uname

Test yourself

Q1. Linux is, strictly speaking, the…
Q2. Most common default server shell is…
Q3. Show the running kernel with…

Discussion

Loading…