在 mac osx 终端中移动或复制 find 调用的结果

Ant*_*neo 8 macos terminal command line

我有一个很大的目录,里面装满了各种形状文件。我想移动或复制所有以 _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
Run Code Online (Sandbox Code Playgroud)

上面的 find 调用成功找到了所有所需的文件。现在我想将这些结果移动或复制到新目录。有任何想法吗?

小智 9

这是 xargs 的工作!

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

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

-I _为随后在 cp 命令中使用的传入线路设置占位符。