gzip */*.txt
But the extension for each file will be .txt.gz, as gzip uses it to know the original filename.
Answer from Juliano on Stack Overflowif you have zip,
zip myzip.zip cvd*.txt
Don't need to tar them first.
You want to tar your files together and gzip the resulting tar file.
tar cvzf cvd.tar.gz cvd*.txt
To untar the gzip'd tar file you would do:
tar xvzf cvd.tar.gz -C /path/to/parent/dir
This would extract your files under the /path/to/parent/dir directory
command line - gunzip multiple files - Unix & Linux Stack Exchange
Compress more than 1 file on a Gzip files
Multiple files in a gzip archive
How to gzip Multiple Files into Unique Zipped Files in One Shot? - Software & Applications - Spiceworks Community
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:
create a new archive- g
zip (alternatives:jfor bzip2,Jfor xz) verbose (list processed files; optional)- output
file (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
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.
This uses gunzip to unzip all files in a folder and have the ending .out.gz
gunzip */*.out.gz
This will "loop"* through all folders that have a zipped file in them. Let me add an example:
A
a.out.gz
B
b.out.gz
C
c.out.gz
D
d.out.gz
E
e.out
Using the command above, a.out.gz b.out.gz c.out.gz d.out.gz will all get unzipped, but it won't touch e.out since it isn't zipped.
*this is called globbing or filename expansion. You might like to read some more about it here.
find . -type f -name "*.gz" -execdir gunzip {} \;
the execdir option to find causes 'find' to 'cd' into each directory in turn and run the exec command (gunzip in this case) and then 'cd' back to the cwd
You can use below command.
Go to the directory where your .gz file is and run command:
for f in *.gz ; do gunzip -c "$f" > /home/$USER/"${f%.*}" ; done
It will extract all file with original name and store it to current user home directory(/home/username). You can change it to somewhere else.
EDIT :
gunzip *.gz
This command also will work. But, by default, it replaces original file.
Option # 1 : unzip multiple files using single quote (short version)
gunzip '*.gz'
Note that *.gz word is put in between two single quote, so that shell will not recognize it as a wild card character.
Option # 2 : unzip multiple files using shell for loop (long version)
for g in *.gz; do gunzip $g; done
The Source
EDIT :
I have just tried :
gunzip -dk *.gz
and it worked.
-d to decompress and k to keep original files.
Sample file
$ ls -1 file-1 file-2
If I just use gzip file-*, the original files will be removed and replaced with individual .gz file
$ gzip file-* $ $ ls -1 file-1.gz file-2.gz $
Is it possible to have a single .gz file while retaining the original files?
Desired output
$ ls -1
file-1 file-2 all.gz
Thanks