Erreur de CP (utilisation combinée avec ls et grep) - cp: can not stat
Question
Quand je fais ls avec grep, le résultat est ce que je exaxtly besoin: une liste de dll, voir ci-dessous:
$ 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
...
Mais quand j'ai essayé de copier tous les dll à dire de destination ../, je suis arrivé erreurs et aucun fichier est copié:
$ 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
...
je pouvoir à cela pour ma version précédente de boost en utilisant Cygwin, mais je ne sais pas pourquoi maintenant il ne fonctionne pas pour stimuler la construction 1-47.
apprecaite toute entrée.
La solution
Vous voyez une liste de dll, mais vous ne savez pas dans quels répertoires ils vivent. Le nom du répertoire est imprimé sur une ligne distincte une fois, et filtré par grep
.
Vous ne pouvez pas utiliser ls -R
pour quelque chose de significatif. Le format de sortie est trop script hostile. Utilisez find
à la place. Cette commande
find . -name "*.dll"
imprimera noms de chemin complet de vos dll (sans avoir besoin d'utiliser grep
). Cette commande
find . -name "*.dll" -exec cp {} ..
copie les fichiers à ..
au lieu d'imprimer leurs noms.