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
- Produce
all.log containing every f.log in one pass (no loop). - Extract only the lines containing
ERROR into errors.txt. - Find every file modified in the last hour under
/lab. - 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