I have a large collection of files contained in directories for testing. I need to keep the directory structure for my application but want to thin out the files for faster testing. I want to limit the number of files a directory can have to 3. How can I do that in linux?
To clarify what I would like to accomplish, a solution in Python:
import sys, os
for root, dirs, files in os.walk(sys.argv[1]):
for index, file in enumerate(files):
if index > int(sys.argv[2]) - 1: os.remove(os.path.join(root, file))
Usage:
python thinout.py /path/to/thin\ out/ <maximum_number_of_files_per_directory>
Example:
python thinout.py testing\ data 3
I found a smiliar question about doing this for one directory, but not recursively.