Prev - Index - Next

The Unix philosophy of small tools

UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.

Doug Gwyn

One of the fundamental concepts of Unix (and therefore Linux) is creating new tools from a wide range of smaller, dedicated tools.

Rather than large monolithic tools that attempt to solve every problem, Unix supplies a broad collection of simple tools that do a limited number of tasks very well. From those simple tools, sophisticated solutions can be assembled on the run.

The disadvantage? A steep learning curve while users familiarise themselves with the various commands, options and combinations.

The advantage? Flexible solutions to difficult problems, quick solutions to trivial problems.

Some examples

Finding the highest UID in /etc/passwd

If I wanted to find the highest user ID in the password file (ignoring the nobody user), I could manually scan /etc/passwd, but that could be tricky if I have 35000 users and the UIDs are jumbled.

Here is a simple solution using four standard Unix tools:

    grep -v nobody /etc/passwd | awk -F: '{print $3}' | sort -n | tail -1

(Have a look at the man pages for grep, awk, sort and tail to see how this works)

Note that I could have done most of this in awk, but I would have needed to check the AWK manual for that! I could have also written it with cut instead of awk and head instead of tail. I could have written it completely in Python, Perl or Tcl.

Forcing all file names in a directory to lowercase.

Some programs will leave MS-DOS files on a Unix filesystem with uppercase names, which sits awkwardly with perfectionists who dwell in the lowercase... This utility uses tr to shift the file names downcase, with help from echo and mv.

# lowerit
# convert all file names in the current directory to lower case 
# only operates on plain files--does not change the name of directories
# will ask for verification before overwriting an existing file
# (Not sure who wrote this!)
for x in `ls`
        if [ ! -f $x ]; then
	lc=`echo $x  | tr '[A-Z]' '[a-z]'`
        if [ $lc != $x ]; then
        	mv -i $x $lc


Linux and Unix give you the freedom to use large tools or combinations of small tools in a myriad of ways that the creators of those tools could never have envisaged, and that developers working with closed operating systems can only dream about.

Use the tools that you feel comfortable with! If you feel happy using ex as your editor to write Chipmunk BASIC code, then do it!

Enjoy the freedom, experiment with different tools, have fun, release your code.

Prev - Index - Next