CP 错误(与 ls 和 grep 结合使用)- cp: 无法统计
当我用 grep 执行 ls 时,结果正是我需要的:dll 列表,见下文:
$ ls -R | grep "dll$"
boost_chrono-vc90-gd-1_47.dll
boost_chrono-vc90-mt-gd-1_47.dll
boost_chrono-vc90-1_47.dll
boost_chrono-vc90-mt-1_47.dll
boost_date_time-vc90-gd-1_47.dll
boost_date_time-vc90-mt-gd-1_47.dll
boost_date_time-vc90-1_47.dll
boost_date_time-vc90-mt-1_47.dll
boost_filesystem-vc90-gd-1_47.dll
boost_filesystem-vc90-mt-gd-1_47.dll
boost_filesystem-vc90-1_47.dll
...
但是当我尝试将所有这些 dll 复制到目的地(例如 ../)时,出现错误并且没有复制任何文件:
$ cp `ls -R | grep "dll$"` ../
cp: cannot stat `boost_chrono-vc90-gd-1_47.dll': No such file or directory
cp: cannot stat `boost_chrono-vc90-mt-gd-1_47.dll': No such file or directory
cp: cannot stat `boost_chrono-vc90-1_47.dll': No such file or directory
cp: cannot stat `boost_chrono-vc90-mt-1_47.dll': No such file or directory
cp: cannot stat `boost_date_time-vc90-gd-1_47.dll': No such file or directory
cp: cannot stat `boost_date_time-vc90-mt-gd-1_47.dll': No such file or directory
cp: cannot stat `boost_date_time-vc90-1_47.dll': No such file or directory
cp: cannot stat `boost_date_time-vc90-mt-1_47.dll': No such file or directory
cp: cannot stat `boost_filesystem-vc90-gd-1_47.dll': No such file or directory
cp: cannot stat `boost_filesystem-vc90-mt-gd-1_47.dll': No such file or directory
...
我我之前使用 cygwin 的 boost 构建曾经能够做到这一点,但我不知道为什么现在它不适用于 boost 构建 1-47。
感谢任何输入。
When I do ls with grep, the result is exaxtly what I need: a list of dlls, see below:
$ ls -R | grep "dll$"
boost_chrono-vc90-gd-1_47.dll
boost_chrono-vc90-mt-gd-1_47.dll
boost_chrono-vc90-1_47.dll
boost_chrono-vc90-mt-1_47.dll
boost_date_time-vc90-gd-1_47.dll
boost_date_time-vc90-mt-gd-1_47.dll
boost_date_time-vc90-1_47.dll
boost_date_time-vc90-mt-1_47.dll
boost_filesystem-vc90-gd-1_47.dll
boost_filesystem-vc90-mt-gd-1_47.dll
boost_filesystem-vc90-1_47.dll
...
But when I tried to copy all those dll to a destination say ../, I got errors and no files is copied:
$ cp `ls -R | grep "dll$"` ../
cp: cannot stat `boost_chrono-vc90-gd-1_47.dll': No such file or directory
cp: cannot stat `boost_chrono-vc90-mt-gd-1_47.dll': No such file or directory
cp: cannot stat `boost_chrono-vc90-1_47.dll': No such file or directory
cp: cannot stat `boost_chrono-vc90-mt-1_47.dll': No such file or directory
cp: cannot stat `boost_date_time-vc90-gd-1_47.dll': No such file or directory
cp: cannot stat `boost_date_time-vc90-mt-gd-1_47.dll': No such file or directory
cp: cannot stat `boost_date_time-vc90-1_47.dll': No such file or directory
cp: cannot stat `boost_date_time-vc90-mt-1_47.dll': No such file or directory
cp: cannot stat `boost_filesystem-vc90-gd-1_47.dll': No such file or directory
cp: cannot stat `boost_filesystem-vc90-mt-gd-1_47.dll': No such file or directory
...
I used be able to to this for my previous boost build using cygwin, but I don't know why now it's not working for boost build 1-47.
Apprecaite any input.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您会看到 dll 列表,但不知道它们位于哪些目录中。目录名称在单独的行上打印一次,并通过
grep
过滤掉。您不能将 ls -R 用于任何有意义的事情。输出格式对脚本太不友好。请改用
find
。此命令find 。 -name "*.dll"
将打印 dll 的完整路径名(无需使用
grep
)。此命令find 。 -name "*.dll" -exec cp {} ..
将把文件复制到
..
而不是打印它们的名称。You see a list of dlls, but you don't know in which directories they live. The directory name is printed on a separate line once, and filtered out by
grep
.You cannot use
ls -R
for anything meaningful. The output format is too script-unfriendly. Usefind
instead. This commandfind . -name "*.dll"
will print full path names of your dlls (no need to use
grep
). This commandfind . -name "*.dll" -exec cp {} ..
will copy the files to
..
instead of printing their names.