Skip to content
rajin

Linux Essentials: Files, Filters & Permissions

Preview~10 min3 steps

You are on a fresh Alpine Linux box. In this lab you will build a small log folder, extract the errors from a noisy log file and protect the result so only you can read it.

Everything happens in ~/workspace. A file called sample.log is already waiting there.

Steps

The sandbox is not running. Launch it to insert commands and verify steps; reading and predicting work without it.

  1. 01Create the log folder

    Create the folder app/logs inside ~/workspace (the -p flag also creates missing parent folders), then create an empty server.log in it with touch.

    • cd ~/workspace
    • mkdir -p app/logs
    • touch app/logs/server.log
    • ls -R app
  2. 02Filter the errors

    sample.log mixes INFO, WARN and ERROR lines. Use grep to keep only the ERROR lines and redirect (>) the result into app/logs/errors.txt.

    • cat sample.log
    • grep ERROR sample.log > app/logs/errors.txt
    • cat app/logs/errors.txt
  3. 03Lock down the file

    Error logs can leak secrets. Use chmod 600 so only the owner can read and write errors.txt, then check it with ls -l (you should see -rw-------).

    • chmod 600 app/logs/errors.txt
    • ls -l app/logs