RHCSAv10 · RHEL 10

Lessons

Essential shell tools

updated 2026-10-19 by seed

Goal

Read and manipulate files from the command line, with no graphical editor. At the exam these tools appear inside nearly every task.

Redirections and pipes

cmd > file           # stdout, overwrite
cmd >> file          # stdout, append
cmd 2> err.txt       # stderr only
cmd > out 2>&1       # both streams
cmd1 | cmd2          # pipe stdout into stdin
cmd | tee log.txt    # show AND write

Searching text: grep

grep -i error /var/log/messages      # case-insensitive
grep -rn "PermitRootLogin" /etc/ssh  # recursive + line numbers
grep -E "^(root|eric):" /etc/passwd  # extended regex
grep -v "^#" file.conf               # drop comments

find: locate by criteria

find /var/log -name "*.log" -mtime -1          # modified in the last 24h
find /etc -type f -perm -o+w                   # world-writable (classic audit)
find /home -user eric -size +10M
find /tmp -type f -delete                      # careful: irreversible

sed: stream editing

sed -i 's/old/new/g' file                      # in-place edit
sed -n '10,20p' file                           # print a range
grep -l pattern /etc/* | xargs sed -i 's/a/b/g'  # over a list of files

Archives

tar czf backup.tar.gz /etc        # create (z = gzip)
tar tzf backup.tar.gz             # list
tar xzf backup.tar.gz -C /restore # extract elsewhere

Verify

echo test | grep -q test && echo OK
find /var/log -name "*.log" | wc -l