Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell 'tar: not found in archive' error when using regular expression

Tags:

linux

shell

tar

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?

like image 847
notbad Avatar asked Jun 05 '13 06:06

notbad


People also ask

How do I archive with tar?

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.

How do you fix tar Exiting with failure status due to previous errors?

To solve the problem, simply adjust the permission of the problematic file (or remove it), and re-run tar .

What is XVF in 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.


1 Answers

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.

like image 145
Igor Chubin Avatar answered Sep 23 '22 23:09

Igor Chubin