|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Find command - Performance
I'm trying write a script to find certain files in a Unix system. I have 3 large directories called /Archive1 /Archive2 and Archive3. I have to find a file in each directory. Here is my script:
#!/bin/bash tt=/usr/tmp/zznineteenzz arch=/usr/tmp/foo.tomk dirs="/Archives /Archives2 /Archives3" for i in `cat $tt`; do for dd in $dirs; do for ff in `.dosu find $dd -name $i*Z -print`; do if [ -f $arch ] then echo $ff >> $arch fi done done done ==== I'm worried about performance issues. Is there a better way? Thanks everyone! |
|
#2
|
|||
|
|||
|
Code:
for dir in "$dirs"
do
find "$dir" -type f -print | grep -f /usr/tmp/zznineteenzz
done > file_listing
This way you read thru each directory only once with find. |
|
#3
|
|||
|
|||
|
Not totally sure, but I think you can do find /dir1 /dir2 /dir3 -type f ... etc., so do all 3 dirs at once - man find will ngive a yea/nay.
|
|
#4
|
|||
|
|||
|
Some find implementations may do that. You mentioned "a UNIX system", this will work anywhere.
Do not confuse the number of lines in a script with performance. The critical step here is just reading thru a directory and then grepping against a list of files contained in /usr/tmp/zznineteenzz |
|
#5
|
|||
|
|||
|
A little quicker (just one command not in an external loop, o shaving off those all important microseconds!
) and also easier/less to type ... ![]() |
|
#6
|
|||
|
|||
|
Try using find and xargs.....
find /path/to/ <anyother find options> | xargs grep 'search value' |
|
#7
|
|||
|
|||
|
Quote:
ignore this I didn't read it right...thought you were looking to find something in a file. My bad! |
|
#8
|
|||
|
|||
|
Since we're beating performance to death here... POSIX find supports a + operator
which improves performance of the -exec clause by having the subprocess command work on a large set of data: Code:
for dir in "$dirs"
do
find "$dir" -type f -print -exec grep -l /usr/tmp/zznineteenzz {} \+
done > file_listing
So, this is another way to approach the problem. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Find command - Performance |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|