Showing posts with label command line. Show all posts
Showing posts with label command line. Show all posts

Sunday, October 07, 2012

Linux Commands - Tree View

Came across a very useful file-structure-view script from this website for a tree view of the directory.

Just replicating here in case the site disappears :-)

#!/bin/sh
#######################################################
#  UNIX TREE                                          #
#  Version: 2.3                                       #
#  File: ~/apps/tree/tree.sh                          #
#                                                     #
#  Displays Structure of Directory Hierarchy          #
#  -------------------------------------------------  #
#  This tiny script uses "ls", "grep", and "sed"      #
#  in a single command to show the nesting of         #
#  sub-directories.  The setup command for PATH       #
#  works with the Bash shell (the Mac OS X default).  #
#                                                     #
#  Setup:                                             #
#     $ cd ~/apps/tree                                #
#     $ chmod u+x tree.sh                             #
#     $ ln -s ~/apps/tree/tree.sh ~/bin/tree          #
#     $ echo "PATH=~/bin:\${PATH}" >> ~/.profile      #
#                                                     #
#  Usage:                                             #
#     $ tree [directory]                              #
#                                                     #
#  Examples:                                          #
#     $ tree                                          #
#     $ tree /etc/opt                                 #
#     $ tree ..                                       #
#                                                     #
#  Public Domain Software -- Free to Use as You Like  #
#  http://www.centerkey.com/tree  -  By Dem Pilafian  #
#######################################################

echo
if [ "$1" != "" ]  #if parameter exists, use as base folder
   then cd "$1"
   fi
pwd
ls -R | grep ":$" |   \
   sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'
# 1st sed: remove colons
# 2nd sed: replace higher level folder names with dashes
# 3rd sed: indent graph three spaces
# 4th sed: replace first dash with a vertical bar
if [ `ls -F -1 | grep "/" | wc -l` = 0 ]   # check if no folders
   then echo "   -> no sub-directories"
   fi
echo
exit

Thursday, October 01, 2009

Linux: All things about Cows...

Recently a friend (Ishan Karve) of mine introduced me to nifty small script/ program called 'cowsay' which has makes life on the Linux command terminal interesting and amusing. Pity, Windows users won't be able to use it.

It is basically a ASCII cow which  moooos...... to you interesting quotes (when linked with the 'fortune' program) or you can make it say un-interesting things as shown below (when used alone!!) :-
__________________________
< My name is Gantayet >
 ----------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||--------w |
                ||     ------||

The program developer Tony Monroe mentions that he decided on this ASCII cow mooing as cows were quite popular in his life!!! Wow! And I thought only Indian revered cows!! He says: "ASCII cows have been wandering in herds around the net for a long time, bringing good will and unnecessary bovine humor to all who meet them"

You can check out the cows grazing on the Internet at this linked site: Canonical list of cows

The program is pretty easy to install - just get the package from Tony Monroe's cowsay site  or if you are on a Debian system (like Ubuntu, Mint etc), just do a 'sudo apt-get -i cowsay' at your command prompt. Post that you can directly run cowsay from the terminal giving it some text to moo about like 'cowsay My name is foo' or pipe fortune quotes like 'fortune | cowsay' at the terminal screen.

Coming to the interesting part: The COW ASCII image has many variation which can be invoked by the -f option to cowsay  (cowsay -f ) . To know what are the options available, just do 'cowsay -l'. This will list all the options availablewhich is pretty interesting. Ok, the options are :

apt beavis.zen bong bud-frogs bunny cheese cower daemon default dragon dragon-and-cow elephant elephant-in-snake eyes flaming-sheep ghostbusters head-in hellokitty kiss kitty koala kosh luke-koala mech-and-cow meow milk moofasa moose mutilated ren satanic sheep skeleton small sodomized sodomized-sheep stegosaurus stimpy supermilker surgery telebears three-eyesturkey turtle tux udder vader vader-koala www
And if you use 'cowthink' instead of 'cowsay', you will get a thinking moooo :-)

Here is an examples when I ran 'fortune | cowsay -f :

fortune | cowsay -f tux
_______________________________________
/ You'll be called to a post requiring    \
\ ability in handling groups of people. /
 ----------------------------------------------------------------
   \
    \
        .--.
       |o_o |
       |:_  / |
      //       \ \
     (|          | )
    /'\_       _/`\
    \___)=(___/


And this Option is interesting ;-) 'fortune | cowsay -f sodomized'
____________________________________________
/ Increased knowledge will help you now. \
\ Have mate's phone bugged.                     /
 ---------------------------------------------------------------------
      \                _
       \              (_)
        \   ^__^       / \
         \  (oo)\_____/_\ \
            (__)\           ) /
                ||---------w ((
                ||            ||>>

 Pretty interesting, yeah??