When I use tar -xzf *.gz
to extract all the .gz
files in the current directory, I get Not found in archive
error. However, it works fine if I extract one by one or use a for-loop like
for file in `ls *.gz`; do tar -xzf $file; done
What is the reason for this error?
The most common uses of the tar command are to create and extract a tar archive. To extract an archive, use the tar -xf command followed by the archive name, and to create a new one use tar -czf followed by the archive name and the files and directories you want to add to the archive.
To solve the problem, simply adjust the permission of the problematic file (or remove it), and re-run tar .
xvf is the Unix-style, short method to implement –extract –verbose –file. So, x stands for extracting the archive, v for displaying Verbose information, and f for specifying a filename.
When you write
tar -xzf *.gz
your shell expands it to the string:
tar -xzf 1.gz 2.gz 3.gz
(assuming 1.gz, 2.gz and 3.gz are in you current directory).
tar
thinks that you want to extract 2.gz
and 3.gz
from 1.gz
; it can't find these files in the archives and that causes the error message.
You need to use loop for
of command xargs
to extract your files.
ls *.gz |xargs -n1 tar -xzf
That means: run me tar -xzf
for every gz
-file in the current directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With