I've got a directory that contains directories that contain directories that contain files. I'd like to select two files at random from each leaf directory. I found this question about selecting from a single directory, but running it in each of several hundred directories would be a pain.
Take the 2-minute tour
×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.
With a fixed depth of the directory structure (per your description, a directory with subsubdirectories with files), you could do something like:
The final If you expect newlines in your filenames, you can switch to zero-terminated list of files. |
|||||||||||||
|
You can do it like this:
This isn't necessarily the most efficient way of doing it though. :) |
||||
|
dir/sub1/subsub1/file1
, or can the depth vary from one leaf directory to another? – Gilles Jun 1 at 21:41