我想对树中 6 个目录下的文件执行一些处理(例如复制)。每个目录级别的目录名称完全不规则(随机数字和字母),在最后一级,我的文件所在的目录大约有 20 个。
一个案例的例子:
cp /000157/DZW123/AHG345/DFR987/000RE7/0025RTZ/file.xxx /destination/file.xxx
Run Code Online (Sandbox Code Playgroud)
具有不同最后级别的相同案例(在其他 19 个中):
cp /000157/DZW123/AHG345/DFR987/000RE7/1298FGT/file.xxx /destination/file.xxx
Run Code Online (Sandbox Code Playgroud)
但在许多其他情况下完全不同:
cp /001154/CVS456/SAQ452/FRO921/000VG5/0032RRT/file.xxx /destination/file.xxx
Run Code Online (Sandbox Code Playgroud)
由于情况不同,循环无济于事。如果有一个解决方案允许我为每个分支直接在树中向下移动 6 个目录(不管命名如何),那似乎最好。我试过 cd +n 但这不起作用。
使用find
这个工作
find / -mindepth 7 -maxdepth 7 -iname '*.txt' -exec echo cp {} /destination \;
Run Code Online (Sandbox Code Playgroud)
*.txt
根据您的需要修改图案,echo
如果您喜欢在屏幕上看到的内容,请删除。