Unable to untar file after tar error

After unsuccessful attempt to make a tar.gz file I can't untar the file. It seems like I have lost it and yet this looks like trivial error one should be able to recover from. Is the content of the file really lost? I have tried all sorts of tar and unzip combinations without success.

OS environment and tar version:

$cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core)  $tar --version |grep tar tar (GNU tar) 1.26 

Steps to reproduce:

[[email protected] test]$ ls file.txt [[email protected] test]$ cat file.txt   hello    [[email protected] test]$ tar cvzf file.txt file.tar.gz   tar: file.tar.gz: Cannot stat: No such file or directory   tar: Exiting with failure status due to previous errors    [[email protected] test]$ cat file.txt    ▒Om7▒▒7▒▒'([[email protected] test]$   [[email protected] test]$ tar xvzf file.txt    [[email protected] test]$ cat file.txt    ▒Om7▒▒7▒▒'([[email protected]    [[email protected] test]$ file file.txt   file.txt: gzip compressed data, from Unix, last modified: Fri Jul 29 18:48:56 2016   [[email protected] test]$   


On the line

$ tar cvzf file.txt file.tar.gz

you have asked to create a compressed archive of the file file.tar.gz, and that the archive should be called file.txt. You have simply swapped the two filenames around.

The file file.txt will be overwritten by an empty compressed tar archive. This is why the subsequent commands displays weird things.

Yes, the original contents of file.txt is now lost. Sorry. Restore from backup.

See also this question.

Category: tar Time: 2016-07-29 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.194 (s). 12 q(s)