1.4 KiB
1.4 KiB
Linux+ 1.5.3: Working with text
grep, cut, awk, sed, tr, sort and uniq on real files: users with a login shell, a config file without its comments, an edit with sed, and a word count.
Before you start
The lab clears away the files the tasks create in /tmp, if they're there.
Ubuntu empties /tmp at boot, so do the tasks without a reboot. Tasks 1, 2
and 4 ask for findings: write them to the files in /root/lab-answers/ that
they name.
Tasks
- Find the users with a UID from 1000 to 59999 (the regular users) with
awk, and write their names, one per line, to
/root/lab-answers/1. - Strip the comments and blank lines from
/etc/ssh/sshd_config, saving what's left to/tmp/sshd.active, and count its lines in the same pipeline. Write the count to/root/lab-answers/2. - Copy
/etc/ssh/sshd_configto/tmp/s.conf. Withsed -i.bak, change thePermitRootLoginline (commented out or not) toPermitRootLogin no, keeping the original as/tmp/s.conf.bak, and compare the two withdiff. - Find the most common word in the bash man page, and write it to
/root/lab-answers/4.
Hints
awk -F: '$3 >= 1000 && $3 < 60000 {print $1}' /etc/passwd.grep -v -E '^\s*(#|$)',tee,wc -l. On the RHEL family only root can readsshd_config:sudo.sed -i.bak 's/^#\?PermitRootLogin.*/PermitRootLogin no/'.man bash | tr -cs 'A-Za-z' '\n' | tr 'A-Z' 'a-z' | sort | uniq -c | sort -rn | head.