4 of 4

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.

  • man
  • apropos
  • info
  • man -k
  • /usr/share/doc
  • --help
  • mandb

35 min5 exercises

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.

  1. command --help prints a short usage summary. Start here for syntax.
  2. man pages 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.
  3. info holds longer manuals for some GNU tools (info coreutils).
  4. /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

KeyAction
Space / bPage down / up
/text, n, NSearch forward, next hit, previous hit
g / GTop / bottom
qQuit
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.

  1. 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 -lt lists newest first and ls -ltr oldest first.

    Hint

    Inside man, type / followed by a word to search, n for the next hit and q to quit.

    Solution
    man ls
    ls -lt ~
    ls -ltr ~
  2. Practice

    Same name, two manuals

    passwd is 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 passwd is the command (section 1). man 5 passwd describes the /etc/passwd file format (section 5). man -f passwd lists 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
  3. 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 (or apropos selinux) lists many entries. If you got nothing appropriate, sudo mandb followed by the search fixes it.

    Hint

    man -k keyword searches names and one-line descriptions. The index is built by mandb.

    Solution
    man -k selinux | head
    sudo mandb
    man -k "security context" | head
  4. Practice

    Find the shipped examples

    Without internet, find the documentation shipped by the rsync package. List the package's documentation files and the directory they live in under /usr/share/doc.

    Check your result

    /usr/share/doc/rsync exists (install rsync first if it does not). rpm -qd rsync lists the documentation files owned by the package.

    Hint

    rpm -qd package lists documentation files. ls /usr/share/doc | grep name finds the directory.

    Solution
    sudo dnf install -y rsync
    ls /usr/share/doc | grep rsync
    rpm -qd rsync
  5. Challenge

    No internet: find how to do it

    You must set a file's SELinux context and have forgotten the exact semanage syntax. 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-fcontext manual page has an EXAMPLE section with a command like semanage fcontext -a -t httpd_sys_content_t "/web(/.*)?". You reached it with man -k fcontext and then man semanage-fcontext.

    Hint

    Start from man -k fcontext. Example sections are usually near the bottom: press G.

    Solution
    man -k fcontext
    man semanage-fcontext