Skip to main content

linux/macOS에서 파일 분할 및 병합 | split, cat



파일을 여러개로 분리할 경우 split 명령어를 사용하고, 합칠 경우 cat 명령어를 이용하면 된다.


1. 파일 분할

split 분할할_파일 출력될_파일_이름
  • -a : 파일 뒤에 붙는 이름의 길이
  • -b : 바이트 크기로 분할
  • -d : 파일이름 뒤에 영문 대신 숫자 붙임
  • -n : 파일을 개수 기준으로 분할

예) test.txt 파일을 1GB씩 분리하고 파일 이름 뒤에 _000, _001, _002 붙이기

split -d -a 3 -b 1G test.txt test.txt_
test.txt_000
test.txt_001
test.txt_002

2. 파일 합치기

cat 병합할_파일 > 출력할_파일

예) test.txt로 시작하는 모든 파일을 test.txt로 병합

cat test.txt* > test.txt

예) test.txt_로 시작하고 마지막 글자가 3글자인 모든 파일을 test.txt로 병합

cat test.txt_??? > test.txt


참고자료