Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

obtain file path

Status
Not open for further replies.

sandeepmur

Programmer
Dec 14, 2003
295
PT
Hi,

I need to find and execute a file under a given dir.. my find cmd is like this:

find /home/bc01/ -type f -name "i_abc.sh" -print

the above cmd is printing 2 lines :

find: cannot search /home/bc01/R1/tmp/m206/data/domain/old
/home/qtbc01/KISS-EAI-R1/tmp/eai_abc.sh

I want to obtain only the 2nd line so I can execute it. something like

fpaths = `find /home/bc01/ -name "i_abc.sh" -print`
echo $fpaths
fpaths

TIA,
sands
 
find /home/bc01/ -type f -name "i_abc.sh" -print [red]| grep -v find[/red]

Cheers.
 
oops, the code actually reads as:

fpaths=`find /home/bc01/ -name "eai_abc.sh" -print`
echo $fpaths
fpaths

echo $paths prints 2 lines..

thnx
 
hi Chacalinc,

nope.. even with the pipe "| grep -v find" it gives the same output as before..

thnx
 
find /home/bc01/ -type f -name "i_abc.sh" -print 2> /dev/null

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
oooohhh... the problem is that the firsts line is echo'ed to STDERR and not STDIN, that's why you cantake it out with grep. hmmm.. it's bad you have no permission in /home/bc01/R1/tmp/m206/data/domain/old.

well, you can filter the var fpath before launch it:

[tt]
fpaths=`find /home/bc01/ -name "eai_abc.sh" -print`
fpaths=`echo $fpaths | grep -v find`
echo $fpaths
fpaths
[/tt]
 
hmmm.. vlad's solution is cleanest than mine.

Cheers vlad (aka vgersh99)
 
hi again,

am afraid i still hv a problem..

I need to find the files under a certain dir.. ex: /abc

Under /abc there exists a link :
lrwxrwxrwx 1 bc01 bc 24 Sep 1 2004 EAI-R1 -> /home/bc01/EAI-R1

So, when I search for a file using the find command, i want it to search the the /abc, all subdirs under /abc and also under the dir /home/bc01. Is this possible ??

thnx
 
In the man find page pay attention to the -follow primary.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
find said:
-follow Always true; causes symbolic links to be
followed. When following symbolic links,
find keeps track of the directories visited
so that it can detect infinite loops; for
example, such a loop would occur if a
symbolic link pointed to an ancestor.
This expression should not be used with the
-type l expression.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
No one has suggested the [tt]-exec[/tt] parameter to run the script. Try this...
Code:
find /home/bc01/ -follow -type f -name "i_abc.sh" -exec {} \; 2>/dev/null
The only problem then is if it finds more than one, it will execute every one it finds.

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top