본문 바로가기
카테고리 없음

linux - copy 고급버전 ; 특정확장자를 포함한 디렉토리+파일복사

by bents 2022. 8. 12.

상황

./에 train, test, val이 있는데 audio가 images안에 모두 들어가 있다.

이런 경우 audio만 따로 분리하고 싶은데 images의 폴더구조를 그대로 유지하면서 복사하는 방법은?

 

find ./ -name "*.wav" -type f -print | cpio -pdm ../audios
  • find . will start in the current directory ie. dir1
  • -mindepth 2 will ignore the contents of the current directory ie. dir1 and include the contents of its sub-directories.
  • -type f -name "*.py" -print will include only files with .py extension.
  • cpio -pdm will copy. -p creates a list of files, -d creates directories as needed and -m sets the correct modification times on directories.
  • ../dir2 will create a directory ( if it does not exist ) named dir2 one level up next to dir1 and copy everything to it.

 

https://askubuntu.com/questions/1222675/copy-all-subdirectory-names-and-files-with-a-particular-extension-to-a-new-direc