
約 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
find
フラグ付きは-exec
それに適しています。デフォルトでは再帰的であり、サブフォルダに降りていきます。
すべての png ファイルをダウンロードから 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 {} +