RHCSAv10 · RHEL 10

Exercises

Exercise: redirections, grep and find

updated 2026-10-19 by seed

Setup

sudo mkdir -p /lab/tools && cd /lab/tools
sudo sh -c 'for i in 1 2 3 4 5; do echo "line $i log $((RANDOM%100))" > f$i.log; done'
echo "ERROR critical" >> f3.log

Tasks

  1. Produce all.log containing every f.log in one pass (no loop).
  2. Extract only the lines containing ERROR into errors.txt.
  3. Find every file modified in the last hour under /lab.
  4. Create /lab/tools.tar.gz without including the tarball itself.

Verify

wc -l /lab/tools/all.log        # 6
cat /lab/tools/errors.txt       # ERROR critical
tar tzf /lab/tools.tar.gz       # f1..f5 + all.log + errors.txt

Solution

cat /lab/tools/f*.log > /lab/tools/all.log
grep ERROR /lab/tools/all.log > /lab/tools/errors.txt
find /lab -mmin -60 -type f
tar czf /lab/tools.tar.gz -C /lab tools