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.