Fastest way to list a file in a folder containing 800,000 files using wildcard

Hi,

I have a directory with possibly around 800,000 files in it.
What is the fastest way to list file(s) in this directory with a wildcard.

for example would

ls -1 *.abcdefg.Z

or

find . -name "*.abcdefg.Z"

be the fastest way to find all of the files that end with .abcdefg.Z in this directory with 800,000 files in it.
Any help or sugestion would be greatly appreciated.

Thx
Jerardfjay

Try them out with "time command":

time ls -1 *.abcdefg.Z
time find . -name "*.abcdefg.Z"

Regards

Looks like ls -1 is faster than find command.
Here are the results.

time ls -1 *.00abcdefg.Z
ABC.00abcdefg.Z
AB.00abcdefg.Z

real    0m2.05s
user    0m0.88s
sys     0m0.96s
 time find . -name "*.00abcdefg.Z"
./ABC.00abcdefg.Z
./AB.00abcdefg.Z

real    33m43.95s
user    0m3.02s
sys     0m29.87s

I am a bit surprised, since I would have imagined the find to be faster. However if there is some other mechanism other than ls -1 available I would be open to trying that as well. Thanks for your input.

Jerardfjay

Assuming no IFS characters in the filenames (otherwise you should change the IFS before running this command):

printf "%s\n" *.00abcdefg.Z

can you check this and tell the time taken?
time find . -name "*.00abcdefg.Z" -maxdepth 1 -type f

You type that command into an interactive shell. Your interactive shell will see *.abcdefg.Z and do all of the work of searching the directory to expand that pattern into a list of files. Once it replaces the pattern with that list it is ready to run that "time" command....

Try:
time ksh -c "ls -1 *.abcdefg.Z"

Perderabo,

Here are the results of timing the ksh -c and ls -1 command.

 time ksh -c "ls -1 *00abcdefg.Z"
ABC.00abcdefg.Z
AB.00abcdefg.Z


real    0m2.31s
user    0m0.87s
sys     0m1.03s

I tried the maxdepth option, however find complains of no such valid argument.

find: 0652-017 -maxdepth is not a valid option.

Thx
Jerardfjay