Split compression / decompression
Created:
Updated:
There are several ways to do split compression/decompression. Here I will introduce some methods.
In this example, a 100MB file is divided and compressed into a 20MB file size
Using “tar”, “split” and “cat” command
Compression
- Files to compress
1 2 3 4 5
$ ls -alh total 101M drwxr-xr-x 2 chuljeon39a chuljeon39a 4.0K Mar 1 22:25 . drwxr-xr-x 30 chuljeon39a chuljeon39a 4.0K Mar 1 14:52 .. -rw-r--r-- 1 chuljeon39a chuljeon39a 100M Mar 1 22:19 100M_filled_with_random_data
- Compression
In this command, we don’t need to specify archive name. Instead, we use “-“ sign.
1 2
$ tar zcvf - 100M_filled_with_random_data | split -b 20M - compressed.tar.gz 100M_filled_with_random_data
- Result
1 2 3 4 5 6 7 8 9 10 11
$ ls -alh total 201M drwxr-xr-x 2 chuljeon39a chuljeon39a 4.0K Mar 1 22:27 . drwxr-xr-x 30 chuljeon39a chuljeon39a 4.0K Mar 1 14:52 .. -rw-r--r-- 1 chuljeon39a chuljeon39a 100M Mar 1 22:19 100M_filled_with_random_data -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 22:27 compressed.tar.gzaa -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 22:27 compressed.tar.gzab -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 22:27 compressed.tar.gzac -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 22:27 compressed.tar.gzad -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 22:27 compressed.tar.gzae -rw-r--r-- 1 chuljeon39a chuljeon39a 17K Mar 1 22:27 compressed.tar.gzaf
Decompression
- Files to decompress
1 2 3 4 5 6 7 8 9 10
$ ls -alh total 101M drwxr-xr-x 2 chuljeon39a chuljeon39a 4.0K Mar 1 22:43 . drwxr-xr-x 3 chuljeon39a chuljeon39a 4.0K Mar 1 22:43 .. -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 22:43 compressed.tar.gzaa -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 22:43 compressed.tar.gzab -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 22:43 compressed.tar.gzac -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 22:43 compressed.tar.gzad -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 22:43 compressed.tar.gzae -rw-r--r-- 1 chuljeon39a chuljeon39a 17K Mar 1 22:43 compressed.tar.gzaf
- Decompression
1 2
$ cat compressed.tar.gza* | tar zxvf - 100M_filled_with_random_data
- Result
1 2 3 4 5 6 7 8 9 10 11
$ ls -alh total 201M drwxr-xr-x 2 chuljeon39a chuljeon39a 4.0K Mar 1 22:46 . drwxr-xr-x 3 chuljeon39a chuljeon39a 4.0K Mar 1 22:43 .. -rw-r--r-- 1 chuljeon39a chuljeon39a 100M Mar 1 22:19 100M_filled_with_random_data -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 22:43 compressed.tar.gzaa -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 22:43 compressed.tar.gzab -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 22:43 compressed.tar.gzac -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 22:43 compressed.tar.gzad -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 22:43 compressed.tar.gzae -rw-r--r-- 1 chuljeon39a chuljeon39a 17K Mar 1 22:43 compressed.tar.gzaf
Using “7z”
Compression
- Files to compress
1 2 3 4 5
$ ls -alh total 101M drwxr-xr-x 2 chuljeon39a chuljeon39a 4.0K Mar 1 23:36 . drwxr-xr-x 30 chuljeon39a chuljeon39a 4.0K Mar 1 14:52 .. -rw-r--r-- 1 chuljeon39a chuljeon39a 100M Mar 1 22:19 100M_filled_with_random_data
- Compression
1
$ 7z a compressed.7z 100M_filled_with_random_data -v20m
- Result
1 2 3 4 5 6 7 8 9 10 11
$ ls -alh total 201M drwxr-xr-x 2 chuljeon39a chuljeon39a 4.0K Mar 1 23:37 . drwxr-xr-x 30 chuljeon39a chuljeon39a 4.0K Mar 1 14:52 .. -rw-r--r-- 1 chuljeon39a chuljeon39a 100M Mar 1 22:19 100M_filled_with_random_data -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 23:37 compressed.7z.001 -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 23:37 compressed.7z.002 -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 23:37 compressed.7z.003 -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 23:37 compressed.7z.004 -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 23:37 compressed.7z.005 -rw-r--r-- 1 chuljeon39a chuljeon39a 5.6K Mar 1 23:37 compressed.7z.006
Decompression
- Files to decompress
1 2 3 4 5 6 7 8 9 10 11
$ ls -alh total 101M drwxr-xr-x 2 chuljeon39a chuljeon39a 4.0K Mar 2 00:11 . drwxr-xr-x 3 chuljeon39a chuljeon39a 4.0K Mar 2 00:11 .. -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 23:47 compressed.7z.001 -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 23:47 compressed.7z.002 -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 23:47 compressed.7z.003 -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 23:47 compressed.7z.004 -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 23:47 compressed.7z.005 -rw-r--r-- 1 chuljeon39a chuljeon39a 5.6K Mar 1 23:47 compressed.7z.006 $
- Decompression
“-aoa” means to overwrite all existing files without prompt. Run the “7z –help” command to get more information.
1
$ 7z x compressed.7z.001 -aoa
- Result
1 2 3 4 5 6 7 8 9 10 11
$ ls -alh total 201M drwxr-xr-x 2 chuljeon39a chuljeon39a 4.0K Mar 2 00:12 . drwxr-xr-x 3 chuljeon39a chuljeon39a 4.0K Mar 2 00:11 .. -rw-r--r-- 1 chuljeon39a chuljeon39a 100M Mar 1 22:19 100M_filled_with_random_data -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 23:47 compressed.7z.001 -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 23:47 compressed.7z.002 -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 23:47 compressed.7z.003 -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 23:47 compressed.7z.004 -rw-r--r-- 1 chuljeon39a chuljeon39a 20M Mar 1 23:47 compressed.7z.005 -rw-r--r-- 1 chuljeon39a chuljeon39a 5.6K Mar 1 23:47 compressed.7z.006
Leave a comment