Which?

Doug's Oracle Blog

  • Home
  • Papers
  • Books
  • C.V.
  • Fun
  • Oracle Blog
  • Personal Blog

Oct 25: Which?

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.
Posted by Doug Burns Comments: (19) Trackbacks: (0)
Defined tags for this entry: Unix/Shell
Related entries by tags:
Paste
Script

Trackbacks
Trackback specific URI for this entry

No Trackbacks

Comments
Display comments as (Linear | Threaded)

#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"

#1.1 - Doug Burns said:
2007-10-25 20:25 - (Reply)

Yes, very nice. Probably better really ;-)

#1.1.1 - 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.

#2 - 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!

#3 - 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. :-O

#3.1 - 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 ;-)

#4 - 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? ;-)

#4.1 - 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.

#4.1.1 - Doug Burns said:
2007-10-26 08:14 - (Reply)

Just realised, you might have meant whereis when talking about all unixes ...

#4.2 - 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!

#5 - 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...

#6 - 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.

#6.1 - Alex Gorbachev said:
2007-10-26 15:31 - (Reply)

Live and learn. Thanks John.

#6.2 - 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.

#6.2.1 - 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

#6.2.1.1 - 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

#6.2.1.2 - 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.

#6.2.1.2.1 - Doug Burns said:
2007-10-29 18:32 - (Reply)

Good call. Old habits die hard. Probably too slowly :-(

#7 - 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)


Add Comment

Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
BBCode format allowed
 
 

Statistics on Partitioned Tables

Contents

Part 1 - Default options - GLOBAL AND PARTITION
Part 2 - Estimated Global Stats
Part 3 - Stats Aggregation Problems I
Part 4 - Stats Aggregation Problems II
Part 5 - Minimal Stats Aggregation
Part 6a - COPY_TABLE_STATS - Intro
Part 6b - COPY_TABLE_STATS - Mistakes
Part 6c - COPY_TABLE_STATS - Bugs and Patches
Part 6d - COPY_TABLE_STATS - A Light-bulb Moment
Part 6e - COPY_TABLE_STATS - Bug 10268597

Comments

Doug Burns about 10053 Trace Files - Different Plan in Different Environments
Tue, 02.04.2013 08:57
You're welcome. Now I just nee d to pull my finger out and ac tually come up [...]
Howard Rogers about 10053 Trace Files - Different Plan in Different Environments
Mon, 01.04.2013 23:08
Makes a big difference, so tha nks for that! With two brow ser windows, o [...]
stelioscharalambides.com about 10053 Trace Files
Sat, 30.03.2013 16:28

Upcoming Presentations

Bookmark

Open All | Close All

Syndicate This Blog

  • XML RSS 2.0 feed
  • ATOM/XML ATOM 1.0 feed
  • XML RSS 2.0 Comments
  • Feedburner Feed

Powered by

Serendipity PHP Weblog

Show tagged entries

xml 11g
xml ACE
xml adaptive thresholds
xml ASH
xml Audit Vault
xml AWR
xml Blogging
xml conferences
xml Cuddly Toys
xml Database Refresh
xml DBMS_STATS
xml Direct Path Reads
xml Fun
xml grid control
xml hotsos 2010
xml listener
xml Locking
xml oow
xml oow2009
xml optimiser
xml OTN
xml Parallel
xml Partitions
xml Patching
xml swingbench
xml The Reality Gap
xml time matters
xml ukoug
xml ukoug2009
xml Unix/Shell
xml Useful Links

Disclaimer

For the avoidance of any doubt, all views expressed here are my own and not those of past or current employers, clients, friends, Oracle Corporation, my Mum or, indeed, Flatcat. If you want to sue someone, I suggest you pick on Tigger, but I hope you have a good lawyer. Frankly, I doubt any of the former agree with my views or would want to be associated with them in any way.

Design by Andreas Viklund | Conversion to s9y by Carl