This question already has an answer here:
这个问题在这里已有答案:
- How to move or copy files listed by 'find' command in unix? 4 answers
如何在unix中移动或复制'find'命令列出的文件? 4个答案
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还需要其他选项。