LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 01-27-2009, 08:19 AM   #1
agrestic
Member
 
Registered: Jan 2009
Location: atlanta, ga, usa
Distribution: sabayon 5, slack64, Lenny, LFS 6.4 user # 20665
Posts: 61

Rep: Reputation: 16
Question make bash search a list of dirs


Hi.
I would like a bash script to quickly search certain directories for executable foo. Can the directories be in a list, like {$HOME/bin,/bin,/usr/bin}? If so, what's the correct syntax?
This is what I have so far.
Code:
if [ ! -f /usr/bin/foo ]; then
...yadda, ya...
But I want it to search directories I specify. IDK if it could use /usr/bin/foo || /bin/foo (in double brackets?), or what.
Googling this i learned echo Total dirs: $(ls -F | grep /$ | wc -l) and a few other things, but no cigar. I'm not sure what a relevant search phrase would be.

TIA.
 
Old 01-27-2009, 08:56 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
What about the following?
Code:
for dir in $HOME/bin /bin /usr/bin
do
  find $dir -maxdepth 1 -name foo
done
The -maxdepth 1 avoids duplicate entries in case one directory is a subdirectory of another one already specified (take in mind that find is recursive).
 
Old 01-27-2009, 09:05 AM   #3
agrestic
Member
 
Registered: Jan 2009
Location: atlanta, ga, usa
Distribution: sabayon 5, slack64, Lenny, LFS 6.4 user # 20665
Posts: 61

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by colucix View Post
The -maxdepth 1 avoids duplicate entries in case one directory is a subdirectory of another one already specified (take in mind that find is recursive).
Excellent! Many many thanks. Especially for the explanation of the maxdepth parameter; man find didn't yield much.

Last edited by agrestic; 01-27-2009 at 09:09 AM.
 
  


Reply


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
Can you make search ...search a string in a link....a url...a web address aus9 LQ Suggestions & Feedback 4 04-16-2008 09:37 AM
recursively list files and dirs based on permission sneakyimp Linux - Software 2 10-16-2007 06:37 PM
bash shell command - delete all .svn dirs DamianS Programming 7 04-28-2007 01:33 PM
vsftpd: Cannot list files, but can change dirs beebopbogo Linux - Networking 9 02-13-2007 02:30 PM
Bash - How to make For read lines instead of words in a list ? landuchi Programming 10 02-15-2006 01:36 PM


All times are GMT -5. The time now is 08:13 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration