Backticks/paths was: sudo blocks aliases
Peter Garrett
peter.garrett at optusnet.com.au
Fri Dec 30 05:26:32 UTC 2005
On Fri, 30 Dec 2005 06:01:57 +0100
"J.Markoll" <j.markoll at free.fr> wrote:
> by the way, the newbie who talks to you (me) would be most happy to
> learn about this one command line: ls -l `which sh`
> it avoids you to 'cd' to '/bin' before invoking 'ls -l', or does it do
> more ?
The "which" command returns the full path for an executable thet is in
your $PATH . For instance in my case
peter at prospero:~ $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games
peter at prospero:~ $ which firefox
/usr/bin/firefox
The "back quotes" or "back ticks" ( `` ) evaluate the expression within
them, so when I type
ls -l `which sh`
It is equivalent to typing
ls -l /bin/sh
In this case ls -l /bin/sh would have been easier - it's just a bad habit
of mine ;-)
If you aren't sure of the complete path though, it can be a handy
shortcut. It can also be used in scripts, of course, although the
equivalent $(which sh) is easier to read.
If , for example, you are installing linux-headers and want an exact match
to your current kernel (as you normally do), you can type
sudo apt-get install linux-headers-$(uname -r)
which expands to the correct kernel version.
Hope that isn't confusing :)
Peter
--
Unix is hard to learn. The process of learning it is one of multiple small
epiphanies. -- Neal Stephenson
More information about the ubuntu-users
mailing list