Best Kept Secret Of Linux – Apropos


It always amazes me how many Unix people do not know about the command: apropos. It’s fabulous!

Here’s where it is useful. Say you are struggling with something. You know there is a command for what you are doing, but forget what exactly the command is. Perhaps, how to list the open files. So you run:

apropos file

a2ps (1) – format files for printing on a PostScript printer
a2ps (rpm) – Converts text and other types of files to PostScript(TM).
access (2) – check user’s permissions for a file
access (3p) – determine accessibility of a file
access.conf [access] (5) – the login access control table file
acct (5) – execution accounting file

zip (rpm) – A file compression and packaging utility compatible with PKZIP.
zipsplit [zip] (1) – package and compress (archive) files
zisofs-tools (rpm) – Utilities for creating compressed CD-ROM filesystems.
zless (1) – file perusal filter for crt viewing of compressed text
zlib-devel (rpm) – Header files and libraries for Zlib development.
zmore (1) – file perusal filter for crt viewing of compressed text
znew (1) – recompress .Z files to .gz files

Since linux handles files really well, there are actually a LOT of possibilities for “file”. On my system, over 1600.

apropos file | wc
1640 16328 117382

Configuration files such as .conf are of type (5).

The commands that can be used at the prompt are of type (1), and (8). By adding grep, you can narrow the results. But I still get over 600 possibilities.

apropos file | grep -i -e “(1)” -e “(8)”


vipw (8) – edit the password or group files
virt-xml-validate (1) – validate libvirt XML files against a schema
visudo (8) – edit the sudoers file
vol_id (8) – probe filesystem type and read label and uuid
wbmptopbm (1) – convert a wireless bitmap (wbmp) file to a PBM
wc (1) – print the number of newlines, words, and bytes in files
webalizer (1) – A web server log file analysis tool
whereis (1) – locate the binary, source, and manual page files for a command
writelog (8) – add a entry to an INN log file

At this point, you can scan visually. Or, use grep some more.

apropos file | grep -i -e “(1)” -e “(8)” | grep -i “open”

gimp-remote [gimp-remote-2] (1) – tells a running GIMP to open a (local or remote) image file
lsof (8) – list open files

Right! lsof! Of course!

makewhatis:
(catman)

Before apropos is useful, you have to run the command: makewhatis

makewhatis (8) – Create the whatis database

makewhatis creates the whatis database, by reading key sections of all the man pages. When I worked on Sun Microsystems operating systems, I remember the equivilent command was catman. Either will take a number of minutes to finish. It’s write once, read many, so you just need to do it the once.

whatis:

Then, you can also use the command: whatis. This is useful when you are instructed to use a command online you haven’t seen before. Before running the command, you can check what it does.

whatis vfs_catia
vfs_catia (8) – translate illegal characters in Catia filenames

Other useful commands that I use include, which and file.

which:

which will tell where exactly a file is located in your search path:

which sysctl
/sbin/sysctl

file:

file will tell you what type of file it is:

file /sbin/sysctl
/sbin/sysctl: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped

There are many types of files:

file /etc/*

/etc/rc5.d: symbolic link to `rc.d/rc5.d’
/etc/rc6.d: symbolic link to `rc.d/rc6.d’
/etc/rc.d: directory
/etc/rc.local: symbolic link to `rc.d/rc.local’
/etc/rc.news: Bourne shell script text executable
/etc/rc.sysinit: symbolic link to `rc.d/rc.sysinit’
/etc/readahead.d: directory
/etc/reader.conf: ASCII English text

You then always can use the man pages for more info. Go to SEE ALSO for related commands.

One of my beefs about the man pages is that they often tell me everything, except what I need to know. In fact, for apropos, the critical fact that you need to first run makewhatis is not found at all in SEE ALSO. Perhaps that’s why it’s not used much.

Usually I just need a simple example that works. I find I get much better info from blogs these days. Why can’t those who write man pages do similar?

Using apropos has allowed me learn many things about unix and linux that I would not have discovered otherwise. You can spend a lot of time with it, and learn heaps.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: