프로그래밍/Unix

[유닉스] 분할 ( split )

미냐님 2020. 4. 20. 22:18
728x90

split

  • 큰 파일을 일정한 크기를 가진 여러 개의 작은 파일로 분할
  • 옵션을 지정하지 않으면 1000행씩 분할
  • 형식 : split [옵션] [파일명]
  • 옵션 :
    • -b n : 크기가 n 바이트인 파일로 분할
    • -n : n행씩 분할
  • 사용 예
    • split test
    • split –50 test

 

행을 기준으로 파일 분할

  • test_split 파일을 30행씩 나누는 방법
$ cp /ets/group test_split
$ wc –l test_split
67 test_split
$ split –30 test_split
$ wc –l x*
30 xaa
30 xab
7 xac
67 total
$

 

바이트를 기준으로 파일 분할

  • test_split 파일을 512바이트씩 분할
    • 512바이트인 파일 xaa와 423바이트인 파일 xab 생성
    • 생성된 파일의 크기를 합치면 원래 파일 크기와 같음
$ wc –c test_split
935 test_split
$ split –b 512 test_split
$ wc –c x*
512 xaa
423 xab
935 total
$
728x90