CP错误(与ls和grep结合使用) - cp:不能统计

时间:2011-07-25 10:50:14

标签: linux cygwin grep ls 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 build 1-47。

建立任何输入。

1 个答案:

答案 0 :(得分:3)

您会看到一个dll列表,但您不知道它们所在的目录。目录名称在单独的行上打印一次,并由grep过滤掉。

您不能将ls -R用于任何有意义的事情。输出格式对脚本不友好。请改用find。这个命令

find . -name "*.dll"

将打印您的dll的完整路径名(无需使用grep)。这个命令

find . -name "*.dll" -exec cp {} ..

会将文件复制到..,而不是打印他们的名字。