位元詩人 技術雜談:Unix is Friend - Overview

Facebook Twitter LinkedIn LINE Skype EverNote GMail Yahoo Email

Unix utilities seem arcane and ancient; however, some people still admire them, whereas mouses and touch screens are ubiquitous. By Unix Power Tools, Oreilly, Unix is rather a hacker's toolbox than a platform to run application program. You can still access Unix interfaces with buttons, menus and windows, but the real power of Unix is beneath the command line. You do not need to be a programmer or geek to use these utilities; even some simple keystrokes bring you powerful things. Like acquainting yourself with a exotic friend, you need some time to get along with Unix.

Unix is taciturn but faithful. If you key in a command without any arugment, Unix will give you only essential output, no more, no less. For example, ls without any argument just print out a list of directories and files, unlike its contemporary dir in Microsoft Windows. If you want to understand these utilities more, you may key in one command with -h or --help or browse their manual with man.

Although Unix is silent, it does not mean Unix is simple. Every command has dozens of arguments to tailor its output. It is almost impossible to remember all commands and their all arguments. When you need them, just help yourself with their help messages or manuals.

Unix is synergetic. Two or more commands can be combined with pipe or arguments. The effect is 1 + 1 > 2. For example, to count how many files in the directory, do this:


$ ls | wc -l
{{< / highlight >}}

Here is another example.  To remove all object files in the directories and subdirectories:

```console
$ find . -regex '.*/.*\.o' -exec rm -f {} ';'
{{< / highlight >}}

Instead of an all-in-one ultimate command, every Unix utilities do well in its own part.  The synergetic power is left to the user.  The more you use Unix, the more power you gain.

Furthermore, Unix utilities can be combined in **shell scripting**.  Shell scripts are like recipes, orchestrating a sequence of commands, or like glues, combining all utilities together.  You may also save your script for later use, saving from repetitive keystrokes.  You can even create your own commands by shell programming.

Here is a simple shell script converting all PDFs in a directory to TXTs:

```console
$ for f in `ls *.pdf`; do pdf2txt.py $f > ${f%.pdf}.txt; done
{{< / highlight >}}

Unix is the paradise for programmers.  Except a few language like C#, ASP or SAS script, Unix offers all levels of programming languages, like C or C++ for serious system or application programming, Perl for system admistration or web programming, or Ruby for Ruby on Rails website development.  Again, Unix does not force you to use an all-in-one integrated development environment; you have the freedom to choose your tools.  You may edit the source code with your favorite editor, control the steps with Makefile, and test your program from the command line.

The knowledge from Unix is persistent.  Unix utilities and shell interfaces have kept virtually the same for decades.  You do not need to give up your skills and re-learn different ones when the system is upgraded.  Switching between Linux or OS X or other Unix is possible.  Some skill even apply to Microsoft Windows, the non-Unix family of operating systems.  For example, you can use Vim or Emacs on Windows.  Perl works on Windows.  You may substitute Cygwin for `cmd`.  You may also check GnuWin32, a port of Unix utilities to Windows.

Some people may worry that Unix is hard to install and manage.  Although using Unix needs some learning, there are many user-friendly Unix or Linux distributions such as Ubuntu, Linux Mint or Mac OS X.  Some of them are pre-installed.  Among them, OS X is the easiest Unix.  You do not have to worry the hardware and software support.  Besides Unix utilities, there are numerous applications on Mac.  There are also applications to co-operate with Windows like Bootcamp or Parallels.  You may also choose a Linux distribution.  The hardware support from Linux is not as rich as that of OS X.  However, you learn more during the daily use and maintance of Linux.

Although you can access many Unix utilities manuals, programming language references and other materials on your system and the Internet.  I still suggest some books of Unix (or Linux).  Utility manuals and language references on system are written in terse sytle and unfriendly toward beginners.  The materials on the Internet are sometimes scattered and snippy; sound judgement is needed to utilize the articles on the net.  There is no single book fitting everyone, you may choose whatever you like.

Perl is a special case in Unix.  Perl has grown into a full general-purpose programming language for decades.  However, Perl borrows many features of other Unix utilities like shell scripting, AWK, and sed.  Therefore, Perl programming is also suitable for an alternative to shell scripting.  Learning Perl saves you from memorizing many Unix commands.  Every Unix users should consider or learn basic Perl.

If you want to give Unix a try, try Linux on LiveCD or install Linux on a virtual machine.  After you gain some familiarity of Unix (or Linux), try dual-boot Windows and Linux, or buy a Mac.  Let Unix become your friend and find the power of Unix.
關於作者

身為資訊領域碩士,位元詩人 (ByteBard) 認為開發應用程式的目的是為社會帶來價值。如果在這個過程中該軟體能成為永續經營的項目,那就是開發者和使用者雙贏的局面。

位元詩人喜歡用開源技術來解決各式各樣的問題,但必要時對專有技術也不排斥。閒暇之餘,位元詩人將所學寫成文章,放在這個網站上和大家分享。