Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Unix Way

Name: Anonymous 2011-10-02 8:59

write one small program to do one thing right
Every unix program i've seen is a monstrosity with enough options and man/info pages to drive people insane.
http://www.go2linux.org/ls-man-page

Name: Anonymous 2011-10-02 17:05

ls does do one thing and does it well. It lists files.

$ ls
file1  file2  file3  filea  fileb  filec


Or it can list a single file.

$ ls file1
file1


Or it can list several files.

$ ls file1 file2 filec
file1  file2  filec


But ls doesn't have to support wildcards because those are provided by the shell.

ls *
file1  file2  file3  filea  fileb  filec


(ls never sees the asterisk, just the files)

But what if wildcards aren't sufficient for searching and the user needs regular expressions? ls doesn't have to provide those either, because the shell provides pipes (|), and grep provides regular expressions.

$ ls | grep '^.*[1-2]$'
file1
file2


ls doesn't have to worry about saving output to a file either, because that's also provided by the shell with >.

$ ls *[a-c] > file1
$ cat file1
filea
fileb
filec


Now let's say the user wants big letters like those provided by figlet?

$ figlet big text
 _     _         _            _  
| |__ (_) __ _  | |_ _____  _| |_
| '_ \| |/ _` | | __/ _ \ \/ / __|
| |_) | | (_| | | ||  __/>  <| |_
|_.__/|_|\__, |  \__\___/_/\_\\__|
         |___/


Should ls provide it? No, because figlet will gladly provide it to ls.

$ ls *[1-3] | figlet
  __ _ _      _
 / _(_) | ___/ |
| |_| | |/ _ \ |
|  _| | |  __/ |
|_| |_|_|\___|_|
               
  __ _ _      ____ 
 / _(_) | ___|___ \
| |_| | |/ _ \ __) |
|  _| | |  __// __/
|_| |_|_|\___|_____|
                   
  __ _ _      _____
 / _(_) | ___|___ /
| |_| | |/ _ \ |_ \
|  _| | |  __/___) |
|_| |_|_|\___|____/


Want ls to list files by a cow? Pipe it through cowsay.

$ ls file[a-c] | cowsay
 ___________________
< filea fileb filec >
 -------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||


Wanna rot13 it?

$ ls | rot13
svyr1
svyr2
svyr3
svyrn
svyro
svyrp


Want the cow to rot13 it?

$ ls *[1-3] | rot13 | cowsay
 ___________________
< svyr1 svyr2 svyr3 >
 -------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||


Want to have a program where the cow tells you your fortune?

$ cat > cowfortune
fortune | cowsay
$ chmod +x cowfortune
$ mv cowfortune ~/bin
$ cowfortune
 ______________________________________
/ You look like a million dollars. All \
\ green and wrinkled.                  /
 --------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||


Do you get the idea? The UNIX philosophy to do one thing and do it well means that ls need not worry about every possible way to list files, and figlet, cowsay and rot13 need not know anything about listing files.

ls is an exception however, since it is THE most commonly used tool, therefore it provides some of its own conveniences like sorting, etc.

If you think Apple ][ and Commodore 64 are funner than UNIX, you're an accountant or a gamer, not a hacker, and you should probably go back to /g/.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List