Unix with the Bash shell is beautiful because you can string a list of simple commands together to instruct computers to do complex things. Folks sometimes refer to this as “sed, grep, awk”. Those are Unix commands with cryptic names – they sound like mysterious incantations of wizardry. And in effect they are.
Here are some examples:
1. What users are on this box?
The /etc/passwd file contains a list of all users the box. To see the last 5 people added to system you can type:
$ cat /etc/passwd | tail – 5
The dollar sign is the prompt (you don’t type that)
the cat command lists out the contents of a file.
Piping that (|) into tail -5 lists the last 5 rows.
The results may look like this:
This shows name, x, user id, group id, description, home directory and default shell for each user. x is a place holder for the password.
The Unix Operating System, born 45 years ago, and the Bash Shell, born 25 years ago – are the two most powerful programming tools ever created.
Unix was the brain child of Ken Thompson and Dennis Ritchie while working in the mid-1960s. Today most of us use a Linux, Linus Torvalds’ variant of Unix release in 1991.
Bash was developed in 1977. It is published under the GNU Public license.
Combined, these two pieces of software make the most formidable tool in any developers arsenal. Unix, is a multi-user, mult-tasking, file system centric core that talks to the computers CPU (its brain), which in turn controls all the computer resources. Bash is a command line shell wrapped around Unix giving humans the ability to interact with the Unix core in a pseudo English way.
This example, typed after the bash prompt ($) reads ‘List files in long format’, or simply ‘L S minus L’:
$ ls -l
The results might look like this:
drwxr-xr-x 2 dlink dev 4096 Sep 28 20:03 200px
-rw-r–r– 1 dlink dev 230678 Feb 8 2014 Angel.jpg
-rw-r–r– 1 dlink dev 46252 Dec 1 2013 Black_Horse.jpg
-rw-r–r– 1 dlink dev 1379310 Apr 25 13:20 Buddha_watercolor.png
-rw-r–r– 1 dlink dev 22673 Sep 28 19:45 Chacmool.jpg
-rw-r–r– 1 dlink dev 52911 Dec 1 2013 Flowers_3-29-2013.jpeg
-rw-r–r– 1 dlink dev 32078 Sep 28 19:45 Good Nature.jpg
The Machintosh Operating System is a Unix variant. The Windows Operating System is not, and should be avoided for all serious development work.
Ask yourself, is it Elegant? Is it a thing of beauty?
If this is some important piece of code that others will be using then it should be written well.
I read once in an old programming book, “Born to Code in C”, that first you need to make it work, then make it beautiful. I code by this rule. So often I find folks don’t spend enough time on the second part.