Oct 25: Which?
If you work on Unix servers, you'll be familiar with long $PATH settings. Sometimes it's difficult to tell which particular version of a command you're using when there are versions scattered around in various locations, some in the PATH and some not. If you want to check which copy of a command you're running, just use the which command. For example, in this PATH (which is pretty short compared to the PATHs on the servers at work)
[oracle@ISP4400 ~]$ echo $PATH /usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/oracle/bin: /u01/app/oracle/product/11.1.0/db_1/bin
if I type in
[oracle@ISP4400 ~]$ java
where is the executable running from? Well, I can check with the which command
[oracle@ISP4400 ~]$ which java /usr/bin/java
I apologise to those for whom this is completely obvious, but there are clearly people out there who don't know this command and I find it useful regularly.
#1 - Laurent Schneider said:
2007-10-25 20:22 - (Reply)
I like type too
$ type ls
ls is /bin/ls
$ type ora
ora is aliased to `cd $ORACLE_HOME'
$ type p
p is a function
p ()
{
$ORACLE_HOME/bin/sqlplus -L -s "/ as sysdba"
#2 - Doug Burns said:
2007-10-25 20:25 - (Reply)
Yes, very nice. Probably better really ![]()
#3 - Pete Scott said:
2007-10-25 20:27 - (Reply)
I always tell my team to use whence forgetting that it is korn shell only... but then I am sad and old...
Another option to which is type
These are truly useful commands, once a customer porting to a new platform rang me to say that Pro C modules would not link run; a quick whence showed me that they were using the wrong copy of the C complier!
#4 - Pete Scott said:
2007-10-25 20:33 - (Reply)
type is a built in command in some shells so:
type type which
should tell you that type is shell built-in and which is not.
#5 - joel garry 2007-10-25 22:28 - (Reply)
I've had this be very useful, sometimes discovering things like environment switching code that simply appends things to the path, getting the wrong $ORACLE_HOME/bin...
I just wish I could figure out how to convince people to comment their code so I can what it. For that matter, try
what $ORACLE_HOME/bin/oracle
I guess that shows the usefulness of it. ![]()
#6 - Doug Burns said:
2007-10-25 22:29 - (Reply)
Yes, we have a few 'environment problems' at work at the moment! This has come in very handy ![]()
#7 - Alex Gorbachev said:
2007-10-26 05:53 - (Reply)
... and if it's not in the path but you still need this damn command - whereis might play the trick.
I'm not sure you find it in all *nix'es (at least not by default) but it usually there on Linux. Syntax may vary as well but basics must be the same.
PS: Good idea to mention those seemingly simple "tricks". Anything for OpenVMS? ;-)
#8 - Doug Burns said:
2007-10-26 08:12 - (Reply)
I'm not sure you find it in all *nix'es (at least not by default)
The only two I checked where Redhat at home and AIX at work.
#9 - Doug Burns said:
2007-10-26 08:13 - (Reply)
Good idea to mention those seemingly simple "tricks".
I agree, particularly when people add comments with alternatives.
Anything for OpenVMS? ;-)
I'll see what I can do, but I haven't worked on the VMS stuff for a while!
#10 - Doug Burns said:
2007-10-26 08:14 - (Reply)
Just realised, you might have meant whereis when talking about all unixes ...
#11 - Marco Gralike said:
2007-10-26 09:07 - (Reply)
"Good idea to mention those seemingly simple "tricks"." ...
My "simple" blog posts about sc en command line options of sqlplus are currently the most read ones...so apparently it is of some use to people...
#12 - John Scott said:
2007-10-26 10:20 - (Reply)
Another command I find very useful is 'apropos', even though I've been using 'Unix' for years sometimes when my mind goes blank and I can't remember the name of some obscure command that I only use once or twice a year then I can use 'apropos' to try and find it.
John.
#13 - Alex Gorbachev said:
2007-10-26 15:31 - (Reply)
Live and learn. Thanks John.
#14 - Andy C said:
2007-10-27 13:38 - (Reply)
Apropos apropos. This is indeed a handy command. However, because I rarely use it and can't remember how to spell it, so I have to use 'man -k' to remind myself.
God. I love Un*x slightly more than I love recursion.
#15 - Doug Burns said:
2007-10-27 17:49 - (Reply)
Yeah, I was wondering about that. I went to check apropos at work on Friday morning and I'm not sure how it's different to man -k
#16 - Pete Scott said:
2007-10-28 13:50 - (Reply)
There is no difference apart from the spelling ![]()
I used apropos to teach myself UNIX...
... which explains a lot
#17 - Paul G. Matuszyk 2007-10-28 19:09 - (Reply)
after running the command use alias - it will tell you the full path to all commands run (including the last one)
#18 - John Scott said:
2007-10-29 08:24 - (Reply)
Doug,
Yeah apropos is pretty much equivalent to 'man -k', personally I find it a bit easier (read 'faster') to type apro and use tab-command completion than typing 'man -k', although there's not much in it if you're already used to typing 'man -k' (or have it aliased).
John.
#19 - Doug Burns said:
2007-10-29 18:32 - (Reply)
Good call. Old habits die hard. Probably too slowly ![]()

