Tips en Trucs 2019

Apropos, waarvoor dient het?

Als je in Linux voor een terminal opdracht hulp nodig hebt, raadpleeg je de man pagina. Maar als je vlug de namen en beschrijvingen van de man pagina's wilt doorzoeken, heb je de opdracht apropos nodig.

Basisgebruik

Doorzoek de man pagina namen en beschrijvingen door een zoekwoord met de apropos opdracht mee te geven:

dany@pindabook:~> apropos dmesg
dmesg: niets gevonden.

Hier gaat duidelijk iets fout. Apropos gebruikt een database van de man pagina's om deze snel te kunnen doorzoeken. Deze database kan je aanmaken en/of bijwerken na het installeren van extra pakketten met de volgende opdracht:

dany@pindabook:~> sudo mandb
[sudo] wachtwoord voor root: 
Processing manual pages under /usr/share/man/ca...
Updating index cache for path `/usr/share/man/ca/man1'. Wait...
Updating index cache for path `/usr/share/man/ca/man9'. Wait...
Updating index cache for path `/usr/share/man/ca/man8'. Wait...
Updating index cache for path `/usr/share/man/ca/man4'. Wait...
Updating index cache for path `/usr/share/man/ca/man3'. Wait...
Updating index cache for path `/usr/share/man/ca/man6'. Wait...
Updating index cache for path `/usr/share/man/ca/man2'. Wait...
Updating index cache for path `/usr/share/man/ca/mann'. Wait...
Updating index cache for path `/usr/share/man/ca/man5'. Wait...
Updating index cache for path `/usr/share/man/ca/man7'. Wait...
done.
Checking for stray cats under /usr/share/man/ca...
Checking for stray cats under /var/cache/man/ca...
Processing manual pages under /usr/share/man/cs...
Updating index cache for path `/usr/share/man/cs/man1'. Wait...
...
Updating index cache for path `/usr/local/man/man7'. Wait...
done.
Checking for stray cats under /usr/local/man...
Checking for stray cats under /var/cache/man/local...
252 man subdirectories contained newer manual pages.
8020 manual pages were added.
0 stray cats were added.
0 old database entries were purged.

Nu de man pagina database aangemaakt/bijgewerkt is, kan je apropos gebruiken om deze te doorzoeken:

dany@pindabook:~> apropos dmesg
dmesg (1)            - print or control the kernel ring buffer
vmcore-dmesg (8)     - This is just a placeholder until real man page has been written

Naar meerdere zaken tegelijk zoeken, kan vanzelfsprekend ook:

dany@pindabook:~> apropos dmesg whereis
dmesg (1)            - print or control the kernel ring buffer
vmcore-dmesg (8)     - This is just a placeholder until real man page has been written
whereis (1)          - locate the binary, source, and manual page files for a command

Exacte zoekacties

Standaard zoekt apropos naar tekenreeksen:

dany@pindabook:~> apropos who
btrfs-filesystem (8) - command group that primarily does work on the whole filesystems
ldapwhoami (1)       - LDAP who am i? tool
w (1)                - Show who is logged on and what they are doing.
who (1)              - show who is logged on
who (1p)             - display who is on the system
whoami (1)           - print effective userid

De resultaten beperken zich niet tot het woord who, maar toont ook resultaten met woorden die de tekenreeks who bevatten. Om de resultaten te beperken tot man pagina's die het woord who bevatten, gebruik je apropos met de optie --exact:

dany@pindabook:~> apropos --exact who
ldapwhoami (1)       - LDAP who am i? tool
w (1)                - Show who is logged on and what they are doing.
who (1)              - show who is logged on
who (1p)             - display who is on the system

Zoeken naar man pagina's waar meerdere zoekwoorden in voorkomen

Apropos zoek bij het opgeven van verschillende zoekwoorden standaard naar man pagina's waarin minstens één van de zoekwoorden voorkomt:

dany@pindabook:~> apropos find search
apropos (1)          - search the manual page names and descriptions
ausearch (8)         - a tool to query audit daemon logs
ausearch-expression (5) - audit search expression format
...
xfindproxy (1)       - locate proxy services
xzegrep (1)          - search compressed files for a regular expression
xzfgrep (1)          - search compressed files for a regular expression
xzgrep (1)           - search compressed files for a regular expression
zgrep (1)            - search possibly compressed files for a regular expression
zipgrep (1)          - search files in a ZIP archive for lines matching a pattern

Om te zoeken naar man pagina's waar beide zoekwoorden in voorkomen, gebruik je de -a (--and) optie:

dany@pindabook:~> apropos -a find search
find (1)             - search for files in a directory hierarchy
find (n)             - search for classes and objects
lfind (3)            - linear search of an array
lfind (3p)           - find entry in a linear search table
tfind (3)            - manage a binary search tree
tfind (3p)           - search binary search tree

Volledige zinnen weergeven

Bij zinnen die langer zijn dan de breedte van de terminal, worden deze met drie puntjes afgebroken.

dany@pindabook:~> apropos who
btrfs-filesystem (8) - command group that primarily does work on the w...
ldapwhoami (1)       - LDAP who am i? tool
w (1)                - Show who is logged on and what they are doing.
who (1)              - show who is logged on
who (1p)             - display who is on the system
whoami (1)           - print effective userid

Om de volledige zinnen weer te geven, gebruik je te optie -l (--long):

dany@pindabook:~> apropos -l who
btrfs-filesystem (8) - command group that primarily does work on the whol
e filesystems
ldapwhoami (1)       - LDAP who am i? tool
w (1)                - Show who is logged on and what they are doing.
who (1)              - show who is logged on
who (1p)             - display who is on the system
whoami (1)           - print effective userid

En verder

Gebruik de man pagina van apropos om alle opties ervan weer te geven:

dany@pindabook:~> man apropos
Man: alle passende pagina's vinden, niet alleen eerste (set MAN_POSIXLY_CORRECT to avoid this)
 * apropos (1)
   apropos (1+1)
Man: Welke man-pagina wilt u zien?
Man: 1+1
Apropos