LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-03-2022, 02:37 PM   #1
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,688
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
finding a command


given a command name, what is the best way to find its full path in order to be able to run that command in a situation where PATH is not set?

i originally have used the shell command "which" to quickly find this. but, recent versions of Ubuntu have merged /bin and /usr/bin such that there is one directory having all these files and references to either go to that one directory. the result is that every name is found in the first of these directories listed in PATH.

so, now, what is the best way?
 
Old 08-03-2022, 03:55 PM   #2
kilgoretrout
Senior Member
 
Registered: Oct 2003
Posts: 2,989

Rep: Reputation: 388Reputation: 388Reputation: 388Reputation: 388
On my recent *buntu and debian installations, /bin is just a symlink to /usr/bin. However, /usr/bin is listed before /bin in PATH so the which command gives the path as /usr/bin/<command>. If no PATH is set or the application is not in PATH, the simplest way I can think of to find its location is with the find command:
Code:
$ sudo find / -iname "<insert command>"
 
Old 08-03-2022, 08:11 PM   #3
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,380
Blog Entries: 28

Rep: Reputation: 6163Reputation: 6163Reputation: 6163Reputation: 6163Reputation: 6163Reputation: 6163Reputation: 6163Reputation: 6163Reputation: 6163Reputation: 6163Reputation: 6163
I normally use whereis. It's specifically for finding commands.

See man whereis for more.
 
1 members found this post helpful.
Old 08-03-2022, 10:23 PM   #4
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,832

Rep: Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218
Set PATH and let the shell find the (short) commands.
Code:
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
 
Old 08-04-2022, 12:23 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,039

Rep: Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347
which works on PATH (see man which). Otherwise you can use locate, find, whereis, you can check your installed packages, and there is a /usr/lib/command-not-found (or something similar), but in general there is no way to identify arbitrary binaries in any system.
 
Old 08-04-2022, 12:19 PM   #6
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,249

Rep: Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323
I’d still use “which”

Last edited by dugan; 08-04-2022 at 12:25 PM.
 
Old 08-04-2022, 12:56 PM   #7
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,688

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
Quote:
Originally Posted by dugan View Post
I’d still use “which”
i failed to explain well what i am looking for. i want to find the one and only "official" path of where a command is generally supposed to be found, like "ls" is supposed be at "/bin/ls".

write a script that checks all the directories listed in PATH and report all rogues and missing commands in the system it is run on, for a full set of command names or those given as arguments.
 
Old 08-04-2022, 04:55 PM   #8
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,249

Rep: Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323
Quote:
Originally Posted by Skaperen View Post
i failed to explain well what i am looking for. i want to find the one and only "official" path of where a command is generally supposed to be found, like "ls" is supposed be at "/bin/ls".
How are you defining that?
 
Old 08-04-2022, 05:13 PM   #9
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,627

Rep: Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556Reputation: 2556
Quote:
Originally Posted by Skaperen View Post
i want to find the one and only "official" path of where a command is generally supposed to be found, like "ls" is supposed be at "/bin/ls".
The question you need to ask is: Who says "ls" is supposed to be there?

The answer is the Filesystem Hierarchy Standard, which defines what must/may go in "/bin" and "/sbin" (and thus their /usr counterparts).

I don't know if anyone has encoded that information into a script, but it wouldn't be difficult to do.

 
Old 08-04-2022, 07:29 PM   #10
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,249

Rep: Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323
Quote:
Originally Posted by dugan View Post
How are you defining that?
Look. I've had people miss the point when I try to make them think like this, so I'll spell it out. There's no such thing.
 
Old 08-05-2022, 12:24 AM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,369

Rep: Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753
Also, define "rogues and missing commands "...

Just because a cmd doesn't exist on a system, it doesn't necessarily mean it should be there. Systems vary enormously...

If your distro is RPM based, the rpm -V (plus more options) can check verify installed pkgs against what the rpmdb says it should be.
See also https://www.cyberciti.biz/tips/reset...ermission.html to fix various errors.
 
Old 08-05-2022, 10:40 AM   #12
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,249

Rep: Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323
I think this is what you’re actually looking for

https://www.sandflysecurity.com/blog...ile-poisoning/

Last edited by dugan; 08-05-2022 at 12:20 PM.
 
Old 08-05-2022, 06:05 PM   #13
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,688

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
Quote:
Originally Posted by dugan View Post
Look. I've had people miss the point when I try to make them think like this, so I'll spell it out. There's no such thing.
no such thing as what? if you are referring to my use of "official", then pay attention to my use of quotes.
 
Old 08-05-2022, 06:16 PM   #14
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,688

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
Quote:
Originally Posted by chrism01 View Post
Also, define "rogues and missing commands "...

Just because a cmd doesn't exist on a system, it doesn't necessarily mean it should be there. Systems vary enormously...
rogues are commands that are there but not what you expect them to be.

missing are commands you expected to be there but are not there.

that systems vary enormously is all the more reason to write such a script.

Quote:
Originally Posted by chrism01 View Post
If your distro is RPM based, the rpm -V (plus more options) can check verify installed pkgs against what the rpmdb says it should be.
See also https://www.cyberciti.biz/tips/reset...ermission.html to fix various errors.
i'll skip this, for now. i no longer have any RPM based distros. when i get a current project ready to deploy on AWS, i might have quite a few. for now, i'm running Xubuntu 20.04.
 
Old 08-05-2022, 06:21 PM   #15
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,688

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
Quote:
Originally Posted by boughtonp View Post
The question you need to ask is: Who says "ls" is supposed to be there?

The answer is the Filesystem Hierarchy Standard, which defines what must/may go in "/bin" and "/sbin" (and thus their /usr counterparts).

I don't know if anyone has encoded that information into a script, but it wouldn't be difficult to do.

i don't know, either. if someone has, i'm sure someone else will chastise me about it while being careful to not say where it is.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Having problems with command line not finding a command? kantuck Linux - General 8 05-29-2022 06:36 PM
Comparing JPEGs and finding matches... or not finding matches. rnturn Linux - General 16 02-20-2018 02:37 PM
Finding files and then finding content within those files... Maeltor Linux - Software 5 03-13-2007 12:06 PM
What is the command for finding the last 3 times the user had logged into the system? Linux_interest Linux - Newbie 3 08-27-2004 05:02 AM
Finding out my video card from the command line devinWhalen Linux - Hardware 3 04-15-2004 11:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:48 PM.

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