Notice
Recent Posts
Recent Comments
Link
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Archives
Today
Total
관리 메뉴

Astro Coke

[Linux] create separate tar files from multiple folders (files) 본문

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 \;