gzip 2 files into one file
Solution 1:
Unlike ZIP, RAR or 7-Zip, for example, gzip
can only compress one file. As you’ve already noted, there is the tar
program which can serialize multiple files into one which makes them ready for gzip
. The traditional Unix philosophy prefers to use multiple simpler and more specialized tools than one monolithic and complicated. In this case, it results in using tar
and gzip
consecutively, resulting in a .tar.gz
(or .tgz
) file.
However, GNU tar
includes the -z
option which compresses the result of the traditional tar
using gzip
in just one command.
.tar.gz
files are mostly created using the -czvf
options:
-
c
reate a new archive - g
z
ip (alternatives:j
for bzip2,J
for xz) -
v
erbose (list processed files; optional) - output
f
ile (the following argument specifies the output file)
In your example, you can use the command:
tar -czvf test.tar.gz file.mp4 bar.txt
Is there any way to watch inner files without decompression with gzip or bzip2?
Yes, your command also works for a .tar.gz
file:
tar -tvf test.tar.gz
Further reading
- GNU TAR Manual page
- 10 quick tar command examples to create/extract archives in Linux
Solution 2:
gzip
is a compressor, not an archiver, but it works well with tar
tar -cvzf file.tar.gz path-to-files-or-directories-to-compress
See man tar
Compression options
-a, --auto-compress
Use archive suffix to determine the compression program.
-I, --use-compress-program=COMMAND
Filter data through COMMAND. It must accept the -d option, for
decompression. The argument can contain command line options.
-j, --bzip2
Filter the archive through bzip2(1).
-J, --xz
Filter the archive through xz(1).
--lzip Filter the archive through lzip(1).
--lzma Filter the archive through lzma(1).
--lzop Filter the archive through lzop(1).
--no-auto-compress
Do not use archive suffix to determine the compression program.
-z, --gzip, --gunzip, --ungzip
Filter the archive through gzip(1).
-Z, --compress, --uncompress
Filter the archive through compress(1).
And yes, you can watch compressed archives the same way.