No, I don’t mean the UK consumer organisation, but a simple *nix command. It’s so simple that I’ve hesitated about blogging about it, but when I keep sharing a small snippet of information and people don’t know it and find it useful, it’s probably worth mentioning here.
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.
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”
Yes, very nice. Probably better really 😉
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!
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.
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. 😲
Yes, we have a few ‘environment problems’ at work at the moment! This has come in very handy 😉
… 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? 😉
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.
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!
Just realised, you might have meant whereis when talking about all unixes …
“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…
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.
Live and learn. Thanks John.
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.
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
There is no difference apart from the spelling 🙂
I used apropos to teach myself UNIX…
… which explains a lot
after running the command use alias – it will tell you the full path to all commands run (including the last one)
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.
Good call. Old habits die hard. Probably too slowly 🙁