I have a directory that contains hundred thousands of files.
I need to list sample of these files (example 10 files), without processing all the files found in the directory which will take too much processing time.
|
I don't think you can sample from the whole file list without reading them all in some way or the other, even on the filesystem level. Unless their names follow a pattern that is (eg. fileXXXXXXX), in which case you could pregenerate a random list of names before accessing the files. For such a large amount of files it would be odd if their names were random. But let's assume you're not that lucky. Using
Two notes here. For some reason, it often also prints an empty filename, so I increased the sample size just in case. The trivial note is not to forget to change the search path (~ here) and the final command. |
|||
|
|
ls -f| tail -n 1000instead of justlsfor the answer in the link – daniel kullmann Jul 13 '12 at 8:09tailis aweful in this case, since it will wait forlsto finish its work!headwould terminate it after reading the 1000 lines it needs. – lynxlynxlynx Jul 13 '12 at 9:33