如何從資料夾和子資料夾中僅複製pdf?

如何從資料夾和子資料夾中僅複製pdf?

我有一個大約有 20 個子資料夾的資料夾,每個子資料夾有 10-15 個子資料夾。有沒有辦法使用 CLI 僅將 PDF 檔案移至新資料夾?

答案1

若要僅複製所有子目錄中的 pdf,請鍵入:

rsync -rv --include '*/' --include '*.pdf' --exclude '*' /path/to/parent/source/directory/ /path/to/Destination/directory

答案2

您可以cp在啟用 bash 的情況下使用globstar(請參閱這個關於遞歸全局的 U&L 問題):

shopt -s globstar 
cp some/folder/**/*.pdf target/folder

或者,find

find some/folder -iname '*.pdf' -exec cp -t target/folder {} +

答案3

findwith -execflag 適合於此。預設情況下,它是遞歸的並下降到子資料夾中

如果我想將所有 png 檔案從 Downloads 移至 Downloads/PNG 資料夾,我會這樣做: find $HOME/Downloads -type f -iname "*.png" -exec mv -t $HOME/Downloads/PNG {} +

就你而言,

find /path/to/top/folder -type f -iname "*.pdf" -exec mv -t /some/other/place {} +

相關內容