새소식

사용팁/System Digging

[openwrt] xz 사용하기

  • -

openwrt 에서 xz를 사용하려면 xz 패키지를 설치해야 합니다.

opkg update
opkg install xz

용량은 2021.04.09 18.06 기준 25KB 정도 됩니다.(출처)

이제 tar 랑 연동해서 쓰면 되는데 openwrt 에 들어가는 대부분의 프로그램은 원래 기능을 다 제공하지 못합니다.

압축할 때 tar cvJf aa.tar.xz *.log 같은 형태로 쓰면 되는데 openwrt 의 tar 는 J 옵션을 지원하지 않습니다...

tar -cOf - *.log | xz -ze - > logs.tar.xz

위처럼 logs.tar 와 같은 파일 이름 대신 - 를 주고 옵션에 대문자 O를 추가해주면 tar 가 압축파일을 만들지 않고 stdout 으로 출력합니다. 이를 - 로 옵션지정해서 xz에게 주면 xz가 stdin 으로 받아 이 역시 stdout 으로 내보냅니다. 현재 파일이 필요하기 때문에 이를 출력 재지정(redirection)하면 우리가 원하는 파일이 생성됩니다. e 옵션은 cpu를 최대한 써서 압축률을 극대화하는 옵션입니다. 생략해도 됩니다. 그 외에 -0 또는 -9 등의 메모리 사용량을 늘려서 압축률을 높이는 옵션이 있는데 필요하신 분은 xz --help 해서 확인하시고 사용하시면 됩니다.

더보기

$ xz --help
Usage: xz [OPTION]... [FILE]...
Compress or decompress FILEs in the .xz format.

  -z, --compress      force compression
  -d, --decompress    force decompression
  -t, --test          test compressed file integrity
  -l, --list          list information about .xz files
  -k, --keep          keep (don't delete) input files
  -f, --force         force overwrite of output file and (de)compress links
  -c, --stdout        write to standard output and don't delete input files
  -0 ... -9           compression preset; default is 6; take compressor *and*
                      decompressor memory usage into account before using 7-9!
  -e, --extreme       try to improve compression ratio by using more CPU time;
                      does not affect decompressor memory requirements
  -q, --quiet         suppress warnings; specify twice to suppress errors too
  -v, --verbose       be verbose; specify twice for even more verbose
  -h, --help          display this short help and exit
  -H, --long-help     display the long help (lists also the advanced options)
  -V, --version       display the version number and exit

With no FILE, or when FILE is -, read standard input.

참고: helpmanual.io/help/xz/ , linux.die.net/man/1/xz

압축 풀 때 tar xvJf aa.tar.xz 같은 형태로 쓰면 되지만 openwrt 에서 J 옵션 지원 안되는 관계로...

xz -cd logs.tar.xz | tar x

위처럼 xz 에서 c 옵션 추가해서 stdout으로 압축을 해제하고 tar 에서 x 명령으로 풀면 파일이 생성됩니다. 풀리는 파일 목록까지 보고 싶으면 tar x 대신 tar xv 라고 주시면 됩니다.

Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.