1831208 Members
2916 Online
110021 Solutions
New Discussion

Help with doing a find

 
SOLVED
Go to solution
TheJuiceman
Super Advisor

Help with doing a find

Hey gang,

Here is what I'm wanting to do...I'm wanting to run a find command on a file containing a list of filenames. How would be the best approach to do this? Thanks!!!
11 REPLIES 11
Patrick Wallek
Honored Contributor

Re: Help with doing a find

What exactly are you trying to accomplish?

You have a list of filenames and you want to run the find command against it? Are you wanting to locate a specific filename in the file? Are you wanting to see if the files are on the system?

I don't understand your question. A little more explanation please.
TheJuiceman
Super Advisor

Re: Help with doing a find

Hey Patrick,

I hope this helps....

I have a file (we'll call it FileA) that has the following entries...

file1
file2
file3

I want to write a script that will do a find on these entries in FileA. The entries in FileA will change periodically. What would be the best approach? Thanks!!!
Joseph Loo
Honored Contributor

Re: Help with doing a find

hi,

u may use grep command alone:

# grep "file"

regards.
what you do not see does not mean you should not believe
TheJuiceman
Super Advisor

Re: Help with doing a find

Hopefully this will better explain....

I have a file with a list of entries in it (FileA). Looks like...

entry1
entry2
entry3

I want to run a find commands like these:

find / -name entry1
find / -name entry2
etc

The thing is that the entries in FileA change. I need to be able to do a find on / looking for these entries. Any thoughts? Thanks again.
Bill Hassell
Honored Contributor
Solution

Re: Help with doing a find

I am also confused about the purpose. If FileA has a list of simple filenames, are you going to search the entire computer for their location? If so, this can have a huge impact on system performance. Here is a simple procedure to locate a specific filename:

STARTDIR=/
cat FileA | while read MYFILE
do
find $STARTDIR -type f -name $MYFILE -exec ll {} \;
done

Ideally, you have an idea where the file is located so you don't have to search the entire filesystem. Just set STARTDIR to that directory to speed things up.


Bill Hassell, sysadmin
TheJuiceman
Super Advisor

Re: Help with doing a find

That got it!!! Thanks!!!
Daavid Turnbull
Frequent Advisor

Re: Help with doing a find

The issue with find is that it is resouce intensive particularly with threads.

A good way to bring a machine to its knees is to kick of a number of simultaneous find commands that search most of the file systems.

If this could be an issue for you perhaps have a look at the man page for the nice command.
Behold the turtle for he makes not progress unless he pokes his head out.
Nguyen Anh Tien
Honored Contributor

Re: Help with doing a find

I can not give you better solution than Bill Hassell's. His solution is the best way
Enjoy
HP is simple
Arturo Galbiati
Esteemed Contributor

Re: Help with doing a find

Hi,
%cat tt
a
b

%cat tt|xargs -i find . -name {} -exec ll {} \;
-rw-r--r-- 1 pe_EU gpsy 0 Jan 18 02:44 a
-rw-r--r-- 1 pe_EU gpsy 0 Jan 18 02:44 b

HTH,
Art
Brian Sealey
New Member

Re: Help with doing a find

Not knowing why you want to do a find I may be missing the point, but the following would work :-

find -name '*' | grep -F -f

Where would be your base directory assuming you have an idea of where they would be, and is your list of files that you already have. Note the single quotes around *.

This would give you a fuller filename (or full if starting from root).

Note that this should be less cpu and IO intensive as it is only doing 1 find, but it really does depend on what you are doing.

Hope this helps,

Brian
TheJuiceman
Super Advisor

Re: Help with doing a find

Great ideas. Thanks everyone