我有大量包含在测试目录中的文件。我需要为我的应用程序保留目录结构,但想精简文件以加快测试速度。我想将一个目录可以拥有的文件数限制为 3。我该如何在 linux 中做到这一点?
为了澄清我想要完成的任务,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))
用法:
python thinout.py /path/to/thin\ out/ <maximum_number_of_files_per_directory>
例子:
python thinout.py testing\ data 3