Chapter 4: Getting help

Exercise: Find answers in manual pages

Answer four practical questions using nothing but the manual pages on workstation: how to sort a listing by size, how to show sizes readably, what each field of /etc/passwd means, and how to create a user's home directory.

Find answers in manual pages

  • Search inside a manual page for an option.
  • Choose a manual section deliberately.
  • Read a SYNOPSIS and an option's description, then use what you found.

Find the ls option that sorts by size

Open man ls, type / -S (with a space on each side of -S) and press Enter. Press q when you have it.

       -S     sort by file size, largest first

Use it with -l on /etc/ssh:

[student@workstation ~]$ ls -lS /etc/ssh
total 572
-rw-r--r--. 1 root root     541716 Sep 30 21:07 moduli
drwxr-xr-x. 2 root root       4096 Oct  2 08:09 ssh_config.d
drwx------. 2 root root       4096 Oct  3 09:25 sshd_config.d
-rw-------. 1 root root       3674 Sep 30 21:07 sshd_config
...output omitted...
-rw-r--r--. 1 root root         98 Oct  3 09:25 ssh_host_ed25519_key.pub

Make the sizes readable

The sizes above are in bytes. Search the same page for an option that prints sizes like 1K and 234M. Try searching for /human.

       -h, --human-readable
              with -l and -s, print sizes like 1K 234M 2G etc.
[student@workstation ~]$ ls -lhS /etc/ssh
total 572K
-rw-r--r--. 1 root root     530K Sep 30 21:07 moduli
...output omitted...

Decode a line of /etc/passwd

head -n 1 /etc/passwd prints root's entry. Which manual page explains its seven fields, and what is the last one?

[student@workstation ~]$ head -n 1 /etc/passwd
root:x:0:0:root:/root:/bin/bash

The file format is in section 5, so man 5 passwd. man passwd would open the command's page in section 1 instead.

           name:password:UID:GID:GECOS:directory:shell
...
       shell       This is  the  program  to  run  at  login  (if  empty,  use
                   /bin/sh).

root logs in with /bin/bash and has /root as its home directory. Chapter 6 goes through every field.

Read useradd's SYNOPSIS and find the home-directory option

Open man useradd. What does its SYNOPSIS require, and which option creates the user's home directory?

SYNOPSIS
       useradd [options] LOGIN

       useradd -D

       useradd -D [options]
...
       -m, --create-home
           Create the user's home directory if it does not exist. The files
           and directories contained in the skeleton directory (which can be
           defined with the -k option) will be copied to the home directory.

The first form needs a LOGIN (the new user's name), with optional options before it. useradd is in section 8, a command for administrators. The skeleton directory it mentions is /etc/skel, which you looked at in chapter 3.

Check which sections a name exists in

[student@workstation ~]$ whatis useradd passwd
useradd (8)          - create a new user or update default new user information
passwd (5)           - password file
passwd (1ossl)       - OpenSSL application commands
passwd (1)           - update user's authentication tokens