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 12-08-2012, 05:52 AM   #1
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,198

Rep: Reputation: 47
List all bin files


When I want to search for a command, I need to find if a file exists in the $PATH directories. I am using following format:
Quote:
echo $PATH | tr ':' ' ' | xargs ls -l
It seems to be working all right but I am not sure if it is covering all directories. Basically, the question is if following format is all right for ls command and will it show all files in all directories put as an argument:
Quote:
ls -l directory1 directory2 directory3 ..
Or is there any better way? Thanks for your help.
 
Old 12-08-2012, 07:32 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by rng View Post
When I want to search for a command, I need to find if a file exists in the $PATH directories.
What's the logic behind that? If a command isn't in your path then you get a "command not found"-like error and furthermore there are the common whatis, whereis, which, apropos and (s)locate commands. So what reason should you have to do things the way you do? And BTW if you still need to split the PATH in BASH then you can temporarily change the IFS or use
Code:
"${PATH//:/ }"
but beware the output of 'ls' shouldn't be used for parsing: if you need to then use 'find' instead.
 
Old 12-08-2012, 08:59 AM   #3
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,198

Original Poster
Rep: Reputation: 47
Sometimes I know of only part of a command, e.g. systemd commands. So I can use the script to find all commands related to systemd.

Can I use following command?
Quote:
echo ${PATH//:/ } | xargs find '{}' | grep -i systemd
I tried and it seems to work all right.
 
Old 12-08-2012, 11:37 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by rng View Post
Sometimes I know of only part of a command, e.g. systemd commands. So I can use the script to find all commands related to systemd.
Say I'm on a machine that has a set of configuration commands and they all start with "system-config" (I'll limit output with "|head -2").
'whatis' doesn't like partial input so you have to know more:
Code:
 ~]$ whatis system-c
system-c: nothing appropriate|head -2
~]$ whatis system-config
system-config-date   (8)  - graphical interface for changing system date and time
system-config-date  (rpm) - A graphical interface for modifying system date and time
but with 'apropos' that's no problem:
Code:
~]$ apropos system-c|head -2
system-config-date   (8)  - graphical interface for changing system date and time
system-config-date  (rpm) - A graphical interface for modifying system date and time
'locate' is even more useful as it allows you to use a regex. Here I anchor with "bin/" as it matches both common bin and sbin directory names:
Code:
locate -er bin/sy.*-conf|head -2
/usr/bin/system-config-authentication
/usr/bin/system-config-date
and note expressions like "^.*local/[sb,b]in/[a,c].*" are no problem.

'man' can behave like whatis and apropos so I won't go into that, this command doesn't display file locations but finds all man pages and allows you to "step" through them. A plain "q" keypress quits displaying the current one and moves on to the next.
Code:
~]$ man -a system-conf*
As you can see there's multiple ways to get what you want (as long as the system can run makewhatis, updatedb and other such cron jobs regularly).

In your case try running
Code:
locate -er bin/system.*
 
Old 12-08-2012, 09:50 PM   #5
rng
Senior Member
 
Registered: Aug 2011
Posts: 1,198

Original Poster
Rep: Reputation: 47
Thanks for your explanations. However, I tried following command but got no output:
Quote:
locate -er bin/*www*
With the earlier command, there is a good output:
Quote:
$ echo $PATH | tr ':' ' ' | xargs ls -l | grep --color='auto' www
lrwxrwxrwx 1 root root 35 Nov 30 15:53 gnome-www-browser -> /etc/alternatives/gnome-www-browser
lrwxrwxrwx 1 root root 31 Nov 30 15:53 x-www-browser -> /etc/alternatives/x-www-browser
Furthermore, there is an additional advantage of color with the grep command.
 
Old 12-09-2012, 06:01 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by rng View Post
I tried following command but got no output
Meaning updatedb doesn't index the location by default, see 'man updatedb.conf'.
 
  


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
Programs in the bin folder (Can I copy bin files) ndaka123488 Linux - Server 2 12-04-2011 06:56 PM
Need advice on a script to search many files for list of terms, append hits to list jimmy the saint Programming 1 07-11-2010 03:59 AM
Can I install rpm.bin or .bin files on Fedora 11 ?? berndtoro Linux - Newbie 8 08-30-2009 01:22 PM
Combines 16000 files into 1 single file > error tb: /bin/cat: Argument list too long guanyu Linux - General 4 02-09-2007 12:33 AM
Installing .bin-files, leave the file in /usr/local/bin/ ? lagu2653 Linux - Software 1 11-08-2005 08:30 PM

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

All times are GMT -5. The time now is 12:58 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