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:
[weshop@demo test]$ ls
file.txt
[filip@demo test]$ cat file.txt
hello
[filip@demo 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
[filip@demo test]$ cat file.txt
▒Om7▒▒7▒▒'([filip@demo test]$
[filip@demo test]$ tar xvzf file.txt
[filip@demo test]$ cat file.txt
▒Om7▒▒7▒▒'([filip@
[filip@demo test]$ file file.txt
file.txt: gzip compressed data, from Unix, last modified: Fri Jul 29 18:48:56 2016
[filip@demo test]$
tar cvzf file.tar.gz file.txtis what you wanted to do at the third step. – user4556274 Jul 29 '16 at 16:44file.txtin that example. The archive name comes before the files you want to add. I am assuming that 'file.txt' has beem overwritten with a gzipped tarball. To test this, rungzip -d file.txtand then dofile file.txt. Alternately if you dont want to replace the gzipped file, do something likezcat file.txt > file.decompressedand then check what it is withfile file.decomprrssed. It is likely to be an emptytararchive. You have overwrittenfile.txtdue to incorrect use of thetarcommand. – Wyatt Ward Jul 29 '16 at 17:11