将“find”找到的文件复制到另一个文件夹[复制]

时间:2021-10-25 23:57:55

This question already has an answer here:

这个问题在这里已有答案:

I want to copy shared libraries found by following command in a certain folder (/path/to/folder/). How can I do this in bash?

我想复制以下命令在某个文件夹(/ path / to / folder /)中找到的共享库。我怎么能用bash做到这一点?

find /usr/lib/python2.7/ -name '*.so' -exec ldd {} \;

1 个解决方案

#1


xargs to the rescue.

xargs救援。

find /usr/lib/python2.7/ -name '*.so' -exec ldd {} \; |
xargs -r cp -t where/is/destination

This ends up effectively collecting the output from ldd to the end of the cp command line.

这最终有效地将ldd的输出收集到cp命令行的末尾。

This will only work correctly if the file names do not contain newlines. Some legacy versions of xargs also need additional options if the input file names may contain whitespace.

只有在文件名不包含换行符时,这才能正常工作。如果输入文件名可能包含空格,则某些旧版xargs还需要其他选项。

#1


xargs to the rescue.

xargs救援。

find /usr/lib/python2.7/ -name '*.so' -exec ldd {} \; |
xargs -r cp -t where/is/destination

This ends up effectively collecting the output from ldd to the end of the cp command line.

这最终有效地将ldd的输出收集到cp命令行的末尾。

This will only work correctly if the file names do not contain newlines. Some legacy versions of xargs also need additional options if the input file names may contain whitespace.

只有在文件名不包含换行符时,这才能正常工作。如果输入文件名可能包含空格,则某些旧版xargs还需要其他选项。