Thursday, March 24, 2016

Compress and Extract file or directory on Ubuntu

Way to compress and extract file or directory in command line.

1. Compress file or directory
$ tar czvf Comptarget.tar.gz /target
- All contents compress under '/target' will be named as 'Comptarget.tar.gz'


2. Split and Compress file or directory
$ tar czvf - /target | split -b 500mb - Comptarget.tar.gz
- You need to split file or directory if target is too big.
- Can compress target and split it by 500mb.
- Output files will be named as Comptarget.tar.gz*
$ tar czvf Comptarget.tar.gz /target
$ split -b 500mb Comptarget.tar.gz
- Same action above line.


3. Merge compressed Compressed.tar.gz*
$ cat Comptarget.tar.gz* > Comptarget.tar.gz
- Merge split files.


4. Merge and extract Compressed.tar.gz*
$ cat Comptarget.tar.gz* > tar xzvf -
- Can merge and extract in an action.


Ref : http://yoonperl.tistory.com/165

No comments:

Post a Comment