Computer Setup
[Linux] create separate tar files from multiple folders (files)
astrodoo
2021. 1. 19. 22:25
source:
여러 폴더를 상응한 이름의 압축파일로 변환하기 위해서는 메크로가 필요하다.
e.g.)
\tmp1
\tmp2
\tmp3
--> tmp1.tar.gz tmp2.tar.gz tmp3.tar.gz
하지만 아래와 같은 간단한 명령어로 쉽게 바꿀 수 있다.
find tmp* -type d -execdir tar cvfz '{}.tar.gz' '{}' \;
- The first argument is the directory you want to begin in, and find the folders (or files)
- Then we will restrict it to find folders only (-type d; if it is files, it should be -type f)
- The -execdir option allows us to run a command on each file found, executing it from the file's directory
- This command is evaluated as tar foloder_name.tar.gz folder_name, for example, since all occurrences of {} are replaced with the actual folder name. This command needs to be ended with \;