在Mac OSX终端中移动或复制find命令的结果

8

我有一个大目录,里面装了许多不同的shapefile文件。我希望把所有以_31.或_32.结尾的文件移动或复制到另一个目录下(Mac OSX系统)。

## Find all shapefiles ending in 31
find ./ -iname '*_31.*' 2>/dev/null

## Find all shapefiles ending in 32
find ./ -iname '*_32.*' 2>/dev/null

以上查找调用成功找到了所有所需的文件。现在我想将这些结果移动或复制到新目录中。有什么建议吗?


1
我使用了 find ./ -iname '_32.' | xargs -I '{}' mv {} ../..,它完美地工作了,谢谢! - Antonio Cotroneo
1个回答

8

这是xargs的一项任务!

find ./ -iname '*_32.*' | xargs -I _ cp _ destination

xargs将获取find命令的输出,并在每行上运行一个命令。

-I _设置了一个占位符,用于传入cp命令中使用的行。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接