
약 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 {} +