Skip to article content
FrontendXLesson 02 / 16

The Linux shell and filesystem

Move from a laptop shell to a safe, observable delivery pipeline: version control, Linux processes and permissions, container images, networking, configuration and secrets, deployment, health checks, observability, rollback, reproducibility and security hardening.

beginner · about 50 minutes · 3 exercises

  • Predict
  • Implement
  • Debug

What you will be able to do

#
  • Navigate the filesystem and describe absolute versus relative paths.
  • Compose commands with pipes and redirection to inspect text.
  • Find files and processes from the shell without a GUI.

Overview

#

The shell is a program that reads commands, expands them, and runs other programs. On a server it is often the only interface you have, so fluency here is a prerequisite for every later lesson.

The filesystem

Linux presents one tree rooted at /. Everything else is mounted into it. Common directories: /etc for configuration, /var for variable data such as logs, /home for user files, /tmp for temporary files, and /usr for installed programs.

snippet.bash
pwd                 # print working directory
cd /var/log         # absolute path
cd ../nginx         # relative path
ls -la              # long listing, include hidden files

Pipes and redirection

A pipe sends the output of one command into the input of the next. Redirection writes output to a file.

snippet.bash
cat access.log | grep " 500 " | wc -l      # count 500 responses
grep -i error app.log > errors.txt          # write matches to a file
command 2>> errors.txt                       # append stderr

> truncates the target; >> appends. 2> redirects stderr and 2>&1 merges stderr into stdout.

Finding things

snippet.bash
find /var/log -name "*.log" -mtime -1        # logs modified in the last day
grep -rn "DATABASE_URL" /etc/app             # search inside files
ps aux | grep node                            # find a running process

Environment

Environment variables are inherited by child processes. export NAME=value sets one for the current shell and its children; env prints them; echo $HOME reads one.

Common pitfalls

  • Running rm -rf with a variable that is empty, which can delete the wrong directory.
  • Confusing > and >> and silently overwriting a log.
  • Assuming a command exists on a minimal image; busybox and distroless images ship far fewer tools.

Exercises

#

Reference answers and expected output are authored, not executed in this browser. Nothing you type is run, and there is no Run or Pass control on this page.

  1. Exercise 1Predict

    What does this command print when there are exactly 7 lines containing the word error in app.log?

    Read the code, then choose the best answer. The reference explanation stays hidden until you respond.
    stimulus.bash
    grep -c error app.log
    
    Choose the best answer
  2. Exercise 2Implement

    Write a one-line command that lists every file under /var/log modified in the last day whose name ends in .log, sorted by size.

    starter.bash
    # find, then sort by size
    

    Reveal the reference answer
    reference.bash
    find /var/log -name "*.log" -mtime -1 -type f -exec ls -l {} + | sort -k5 -n

    Authored expected output: A list of matching .log files ordered from smallest to largest by byte size.

    find filters by name, modification time and type. -exec ls -l adds sizes, and sort -k5 -n orders by the size column numerically.

  3. Exercise 3Debug

    A deploy script does rm -rf $BUILD_DIR/* and one day wipes the home directory. What is the bug and the safe fix?

    starter.bash
    rm -rf $BUILD_DIR/*
    

    Reveal the reference answer
    reference.bash
    When BUILD_DIR is unset or empty, the command becomes rm -rf /*. Fix it by validating the variable first and quoting it: : "${BUILD_DIR:?BUILD_DIR must be set}" && rm -rf "$BUILD_DIR"/*

    Authored expected output: The script aborts with an error when BUILD_DIR is unset instead of deleting the wrong path.

    Unquoted variables expand to nothing when unset, so the glob becomes a root-level wildcard. The :? expansion fails fast, and quoting prevents word splitting and globbing on the path itself.

Common misconceptions

#
  • The shell is the operating system: it is an ordinary program that launches other programs.
  • rm deletes files to a recoverable trash: on most servers rm unlinks the file immediately.

Follow-up practice

#
  • devops-processes-signals

Related resources

#

Your progress

#

Answers, drafts and completion marks are stored only in this browser. Nothing is sent to a server and no account is used.

Verification: authored. Answers and outputs on this page are authored reference material, not executed results.

© 2026 FrontendX. All rights reserved.