04-23-2007 11:14 PM
I have a file which contains a list of filenames which i have to search in the whole filesystem (root /). I have used a script like
cat file|while read FILENAME
find / -name $FILENAME
But this is running damn slowly and i fear it may take years to complete this command.
Any one help me out plzzz
04-23-2007 11:44 PM
If you truly mean the whole file system, visting every mountpoint, then:
# find / -type f -name ...
...will do that AND potentially take a long time.
If you don't want to visit mountpoints then add the '-xdev' switch as noted:
# find / -xdev -type f -name ...
Notice that in either case I specified only *files* with the '-type f' argument. Drop that if you truly want both files and directories.
Lastly you can reduce the number of searches by doing something like:
# find / -xdev -type f -name myfile -o -name yourfile -o -name "her*" -o -name "his*"
That is, look for files by individual name and perhaps using wildcards. Be sure to quote the metacharacters so that the shell doesn't interpret them.
04-24-2007 12:56 AM
You may also consider breaking you code into several parts so that you can launch them in parallel.
04-24-2007 01:20 AM
find /home/some_user /var/tmp /tmp -name $FILENAME
If you are looking for a particular command, start with the man pages, then look in the system directories and application directories:
find /usr/bin /usr/sbin /use/lbin /usr/local /usr/contrib /opt/*/bin -name $FILENAME
A typical HP-UX system installation has several thousand files in several hundred directories, most of which you never need to search.
Is there a reason you need to look in every directory in the entire machine?
04-24-2007 02:20 AM
1) Run find once and write the output to a temporary file - preferably with filters to restrict it to specific filesystems and to restrict it to regular files.
2) Scan this list of files using grep to find the matches.
04-25-2007 02:47 PM
04-25-2007 03:29 PM
~hope it helps
04-25-2007 04:18 PM - edited 10-05-2011 08:14 PM
>any faster way of searching?
As HGH, JRF and Clay (Plan B) have suggested, you want to do one find, then grep with your list of files. Your original while/find would do N finds.
One advantage of Plan B is that you can look for a filename that wasn't in your "file".
> find / -xdev -type f -name myfile -o -name yourfile -o -name "her*" -o -name "his*"
If you are going to mix AND with OR, you need to use ():
# find / -xdev -type f \( -name myfile -o -name yourfile -o -name "her*" -o -name "his*" \)
04-27-2007 07:49 PM
You can add -type f (type is file, -d dir, etc.)
(find / -type f -name $FILENAME)
or even add -mtime -12 (within the last 12 days) or +12 (12 + days)
(find . -type f -mtime -1300 -name $FILENAME)
to make it faster the search operation.
Also see the -atime, -mtime and -user (owner of the file, etc to make your search faster.
See man find
04-28-2007 12:18 AM
> filesystem (root /).
> Its not tat i want to search in root. I
> just gave an example.
Sometimes it's helpful to ask the question
for which you actually want the answer.
> cat file|while read FILENAME
Knowing, even approximately, what is in
"file" might also be helpful in deciding
which of the techniques already suggested
would be good or bad.