Sunday, December 7, 2008

Long "which" command form

To display not only where is location of which argument,
but also attributes, and if it is symlink, on what binary this symlink points.

example of usage:


rtg@kubic-roman:~$ lwhich mine
error:no such
rtg@kubic-roman:~$ lwhich which
lrwxrwxrwx 1 root root 10 2008-05-01 01:30 /usr/bin/which -> /bin/which
rtg@kubic-roman:~$ lwhich nawk
lrwxrwxrwx 1 root root 22 2007-10-20 04:33 /usr/bin/nawk -> /etc/alternatives/nawk
rtg@kubic-roman:~$ ls -la /etc/alternatives/nawk
lrwxrwxrwx 1 root root 13 2008-05-01 16:49 /etc/alternatives/nawk -> /usr/bin/gawk


To use:
add in your .bashrc :


function lwhich
{
awhich=`which $1`
if [ "a$awhich" != "a" ] # or just if [ $awhich ]
then
ls -l $awhich
else
echo "error:no such"
fi
}


(re)start bash shell.

No comments: