You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: compression.md
+44-11
Original file line number
Diff line number
Diff line change
@@ -64,9 +64,13 @@ To a dir:
64
64
65
65
ZIP every file in cur dir to file.zip
66
66
67
-
#tar tar.gz tgz tar.bz2 tb2
67
+
#tb2
68
68
69
-
Name origin: tape archive.
69
+
#tgz
70
+
71
+
#tar
72
+
73
+
Name origin: `Tape ARchive`.
70
74
71
75
The tar *format* is specified by POSIX 7 together with the `pax` utility: <http://pubs.opengroup.org/onlinepubs/9699919799/utilities/pax.html#tag_20_92>
72
76
@@ -83,10 +87,6 @@ It is a popular option to transform directories in to files in Nix systems, as t
83
87
84
88
Since tar offers no compression, it is often coupled with `gz` and `bz2`: those are files compressors.
85
89
86
-
`.gz` gives similar compression ration as `.zip`
87
-
88
-
`.gz2` gives more compression than `.gz` (30% for ROMs), but is much slower to make, and you can't extract individual files easily.
89
-
90
90
tar end compressions are used so commonly together that shorthand extensions exist for them:
91
91
92
92
-`tgz` == `tar.gz`
@@ -127,25 +127,33 @@ Extract:
127
127
tar vxzf "$F".tgz
128
128
tar vxjf "$F".tbz
129
129
130
+
#zlib
131
+
130
132
#gzip
131
133
132
134
#gunzip
133
135
134
136
#gz
135
137
136
-
gzip files.
138
+
Extension: `gz`.
139
+
140
+
Library name: zlib, GNU.
141
+
142
+
Popular wrapper: `gzip`, and `gunzip` to unzip.
137
143
138
144
Vs zip:
139
145
140
146
- Completely different file types.
141
147
142
-
- Both are use the DEFLATE algorithm: <https://en.wikipedia.org/wiki/DEFLATE>, and therefore have very similar compression ratios and speeds.
148
+
- Both use the DEFLATE algorithm: <https://en.wikipedia.org/wiki/DEFLATE>, and therefore have very similar compression ratios and speeds.
149
+
150
+
- The zlib library does not focus on directories: only single files. For this reason it is commonly used together with `tar` which only packs directories into a file. For convenience however, the command line executable can deal with `.tgz` files.
143
151
144
-
- gzip seems to have very one dominant implementation: GNU, so that gzip can refer to either the utility or format used by that utility.
152
+
- gzip seems to have very one dominant implementation: GNU zlib, so that gzip can refer to either the utility or format used by that utility.
145
153
146
-
zip has many implementations: WinRAR, WinZip on closed source on Windows, Info-ZIP and libzip open source, Info-ZIP being the default one present on Ubuntu 12.04. Therefore the term zip usually onlre refers to
154
+
zip has many implementations: WinRAR, WinZip on closed source on Windows, Info-ZIP and libzip open source, Info-ZIP being the default one present on Ubuntu 12.04. Therefore the term zip usually only refers to the file format.
147
155
148
-
If a file is only gz but not tgz you cannot use tar to extract it
156
+
If a file is only `.gz` but not `.tgz` you cannot use tar to extract it.
149
157
150
158
Create `a.txt.gz` and `rm``a.txt`:
151
159
@@ -155,6 +163,31 @@ Extract `a.gz` and erase it if successful:
155
163
156
164
gunzip a.gz
157
165
166
+
`.gz` all files under given directory recursively individually. Remove each original:
167
+
168
+
gzip -r .
169
+
170
+
##Hardlinks
171
+
172
+
##Keep original
173
+
174
+
Does not work if the file has any hard links, probably because that would not reduce memory usage as it breaks the hardlink. AKA: tries to be too smart and annoys us to hell!
175
+
176
+
Workaround: keep the original on the operations: <http://unix.stackexchange.com/questions/46786/how-to-tell-gzip-to-keep-original-file>
177
+
178
+
Workarounds: `-c` outputs to stdout:
179
+
180
+
gzip -c a > a.gz
181
+
182
+
Read input from stdin:
183
+
184
+
gzip < a > a.gz
185
+
186
+
And finally, `gzip` 1.6 (2013) has the `-k, --keep` option:
187
+
188
+
gzip -k a
189
+
gzip -kr .
190
+
158
191
#RAR
159
192
160
193
Proprietary `Roshal ARchive`, after it's creator Eugene Roshal.
0 commit comments