2014-03-04 71 views
0

我試圖在一個目錄中找到一組數目的文件,然後使用find和cp命令將它們複製到另一個目錄。Linux CLI find和cp問題

這是命令我到目前爲止:

find /usr/share -name a* -type f -group admin -size -10240c | cp /usr/share/ ./thecopy/ 

現在它找到文件,但不復制我試圖向他們發送文件的位置,但發現有問題的文件。 有什麼建議嗎?

+0

這可能屬於[su]。但是你需要在管道之後使用xargs,或者其他的東西。第二個命令只是複製/ usr/share /到./thecopy/就是這樣。 – hometoast

回答

0

試着這麼做:

find /usr/share -name a* -type f -group admin -size -10240c | cp {} ./thecopy/ \; 

{}是如果你想留住你可以嘗試這樣的目錄結構符合您的標準

這些文件的佔位符:

find /usr/share -name a* -type f -group admin -size -10240c | rsync -av {} ./thecopy/ \; 
0
find /usr/share -name a* -type f -group admin -size -10240c -exec cp {} ./thecopy/\; 

這不會在該拷貝下重新創建任何目錄結構。但將它找到的文件複製到您需要的目錄

+0

嘿試過你的建議,我得到這個錯誤:找到:缺少參數到'-exec'任何想法我失蹤? – Gasric

+0

解決了這個問題,但是您提供的幫助解決了我的問題,謝謝! – Gasric