Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-06-2007, 04:15 PM   #1
Registered: Sep 2005
Location: New Jersey, (Which Exit LOL), USA
Distribution: Centos 6.7 Under VMware in Win7
Posts: 455

Rep: Reputation: 34
Question WHICH Command

I'm running SuSE 10.2.

I can execute the which command only if I'm logged in as the root user or I su into root.

How can I enable things so as to allow all users to use the which command?

Old 08-06-2007, 04:26 PM   #2
Registered: Oct 2006
Location: London
Distribution: Arch
Posts: 183

Rep: Reputation: 31
I wouldn't recommend it, but you need to log in as root, and then change the permissions of the which executable. Something along the lines of:

chmod u+x /bin/which
(Note: which may be in a different directory)

I don't recommend this as you will be giving all users access to this command.
Old 08-06-2007, 05:07 PM   #3
LQ Guru
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 130Reputation: 130
I guess you could create a which group and include any users in it that are allowed to make use of that command.
Old 08-07-2007, 08:25 AM   #4
Senior Member
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,820

Rep: Reputation: 610Reputation: 610Reputation: 610Reputation: 610Reputation: 610Reputation: 610
.. what's so dangerous about which .. ?

Originally Posted by man which
which - locate a command
which returns the pathnames of the files which would be executed in the current environâint all matching pathnames of each argument
It comes -rwxr-xr-x on my Debian Etch systems..
Old 08-07-2007, 09:21 AM   #5
Senior Member
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
cat <<EOF >>~/.profile
function which { 
   IFS=:; for x in \$PATH; do
      if [ -x \$x/\$1 ]; then echo \$x/\$1; return 0;fi
   echo "\$1 not fount in \$PATH"
   return 1

Last edited by Agrouf; 08-07-2007 at 09:28 AM.
Old 08-07-2007, 09:30 AM   #6
Registered: Sep 2005
Location: New Jersey, (Which Exit LOL), USA
Distribution: Centos 6.7 Under VMware in Win7
Posts: 455

Original Poster
Rep: Reputation: 34
Thanks everyone. Personnely I like the group idea best.
Old 08-07-2007, 01:42 PM   #7
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
You never elaborated on what happens when you run which
as a normal user, or how the failure manifests itself.

Old 08-08-2007, 02:20 PM   #8
Registered: Oct 2006
Location: London
Distribution: Arch
Posts: 183

Rep: Reputation: 31
.. what's so dangerous about which .. ?
I don't know. But if it is set to root only by default I would have thought it would be done so for a reason. Perhaps not.
Old 08-08-2007, 02:51 PM   #9
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
Check if the which command is in /usr/bin/. It may not be installed.

On my system, which is aliased to _which. _which is a function, so you may not have the alias or function defined.

Su to root and look at "type which". If it is an alias, try using "type <the alias>", as in "type _which" in my example.
Then investigate why the alias or function and the binary don't exist for a regular user.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a single command to list all hardware installed (command line)? davee Linux - Hardware 6 02-28-2009 07:19 PM
Require Linux/Perl equivalent command for windows Command alix123 Programming 7 08-19-2005 02:23 AM
Redirecting output to a command-line argument of another command madiyaan Linux - Newbie 1 02-19-2005 04:35 PM
Key stroke/command to shut down x and go into the command prompt screen? Fear58 Linux - General 1 07-14-2004 07:14 PM
Where is Command line utility for Cups and command tutorial mossy Linux - Software 8 01-16-2004 12:24 AM

All times are GMT -5. The time now is 08:16 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration