Shell FluencyLesson 4 of 4
Finding answers offline: man, info and /usr/share/doc
On the exam there is no internet. Find the command, the option and the example in the system's own documentation.
manaproposinfoman -k/usr/share/doc--helpmandb
After this lesson you can
- Open the right section of a manual page and search inside it.
- Find a command when you only know what it should do.
- Locate example configuration and sample files shipped with a package.
The idea
During the exam you have no internet, but the documentation that ships with the system is there. Using it quickly is a skill in its own right. There are four sources, from the fastest to the most complete.
command --helpprints a short usage summary. Start here for syntax.manpages are the reference. Each belongs to a numbered section: 1 commands, 5 file formats and config files, 8 administration commands. The same name can exist in several sections.infoholds longer manuals for some GNU tools (info coreutils)./usr/share/doc/<package>holds README files, sample configurations and licences shipped by each package.
When you do not know the command name, search by meaning: man -k word (the same as apropos) searches the one-line description of every manual page. It reads an index that mandb builds, so on a fresh system you may need to run sudo mandb once.
Try it
ls --help | head -3
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
man -f passwd
passwd (1) - update user's authentication tokens
passwd (5) - password file
Moving around inside man
| Key | Action |
|---|---|
Space / b | Page down / up |
/text, n, N | Search forward, next hit, previous hit |
g / G | Top / bottom |
q | Quit |
man -k "sort lines"
sort (1) - sort lines of text files
rpm -qd rsync
/usr/share/doc/rsync/NEWS.md
/usr/share/doc/rsync/README.md
/usr/share/man/man1/rsync-ssl.1.gz
/usr/share/man/man1/rsync.1.gz
/usr/share/man/man5/rsyncd.conf.5.gz
Going further
The EXAMPLES or EXAMPLE section near the end of a page is usually the fastest way to the right syntax. man -K text searches inside the full text of all pages (slow). dnf provides '*/semanage' tells you which package to install when a command is missing, and rpm -ql package lists everything a package installed.
Practice
0 of 5 done
Do these on your own system. They get harder. Check each result, then tick it off.
- Warm-up
Find an option in a man page
Open the manual page for
ls. Without leaving the pager, find the option that sorts by modification time, newest first, and the one that reverses any sort. Quit.Check your result
You found
-t(sort by time) and-r(reverse).ls -ltlists newest first andls -ltroldest first.Hint
Inside
man, type/followed by a word to search,nfor the next hit andqto quit.Solution
man ls ls -lt ~ ls -ltr ~ - Practice
Same name, two manuals
passwdis both a command and a file format. Show the first lines of each manual and name the section number of each.Check your result
man 1 passwdis the command (section 1).man 5 passwddescribes the/etc/passwdfile format (section 5).man -f passwdlists both.Hint
Give the section number before the name:
man 5 passwd.Solution
man -f passwd man 1 passwd | head -5 man 5 passwd | head -5 - Practice
Find a command by what it does
You need a tool that shows the SELinux context of a file but do not remember its name. Use a keyword search of the manual page descriptions to find candidate commands. If the search finds nothing, rebuild the index first.
Check your result
man -k selinux(orapropos selinux) lists many entries. If you gotnothing appropriate,sudo mandbfollowed by the search fixes it.Hint
man -k keywordsearches names and one-line descriptions. The index is built bymandb.Solution
man -k selinux | head sudo mandb man -k "security context" | head - Practice
Find the shipped examples
Without internet, find the documentation shipped by the
rsyncpackage. List the package's documentation files and the directory they live in under/usr/share/doc.Check your result
/usr/share/doc/rsyncexists (installrsyncfirst if it does not).rpm -qd rsynclists the documentation files owned by the package.Hint
rpm -qd packagelists documentation files.ls /usr/share/doc | grep namefinds the directory.Solution
sudo dnf install -y rsync ls /usr/share/doc | grep rsync rpm -qd rsync - Challenge
No internet: find how to do it
You must set a file's SELinux context and have forgotten the exact
semanagesyntax. Using only the system documentation, find the example that adds a file-context rule for a custom web directory, and write down the command it shows. Do not use a browser.Check your result
The
semanage-fcontextmanual page has an EXAMPLE section with a command likesemanage fcontext -a -t httpd_sys_content_t "/web(/.*)?". You reached it withman -k fcontextand thenman semanage-fcontext.Hint
Start from
man -k fcontext. Example sections are usually near the bottom: pressG.Solution
man -k fcontext man semanage-fcontext