There are a number of options to standard UNIX commands that are not necessarily well-known or widely used.  As your expertise grows, these lesser known options can speed up your processing considerably, making you more productive.

For example, there is the ls command.  Of course, ls may have been the first command to list as a bug: “Has too many options.”  However, many of these will help you if you remember them.

To list files one per line, use the -1 (one) option.  This can be useful to override default options or to force a plain and generic single column output.

To list all arguments as if they were files, use the -d option.  This doesn’t sound like much at first, but can be very useful.  The best example would be a listing with a wildcard in it: the shell expands the wildcard, then any directory in that list will have the files in it listed in the output.  For the cleanest output, use the wildcard as desired and add the -d option: this will prevent ls from listing the directory.

If you want to see if two different files are the same file – i.e., hard-linked – use the -i option to list inodes.  The inode number for a hardlinked file will match for all of its links.

For looking for manual pages, use the -k option to find all man pages with that specific topic in the header.  The topic is specified as an argument.  For example, see what man -k wireless gets you.

Gzip is another one with some useful options.  The most useful gzip option that is perhaps not widely used is the -c option: this will generate the output onto the stdout stream – which permits it to be piped into another program, such as tar.  Since gzip and gunzip are the same program (with different settings), the -c option can be used for gunzip as much as for gzip.

The make program also has some handy options.  One particularly useful option is -C: when specified with a directory, -C tells make to change to that directory before running.  This means you can run make from anywhere and tell it to act on a makefile somewhere else.  For example, how about this for NIS map management?

make -C /var/yp

It doesn’t matter where you run that from, it will work.

The sudo program has some very useful options.  When you run sudo, you trigger a five-minute countdown (or whatever time is set in the configuration).  When this time runs out, you are asked for your password again when you run sudo.

However – the -v option allows you to restart that clock from the beginning, entering your password if necessary.  It also does not take any commands to run (as that would be superfluous).

The -k option to sudo can be just about as useful: the -k option stops the countdown and resets any clock back to zero.  The next time you use sudo, it will ask for password.

Blogged with the Flock Browser

Tags: , , , , , ,