I was in needed of backing up a .img file, basically what I had to do was to compress the file and copy it to another location. On the begining this file was a +800GB file, so I ran this command:
tar -cvf file.img file.tar
Of course that I didn't see the problem of the command till this was promped
tar: fle.tar: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
Now I ran the command properly after that error
tar -cvf file.tar file.img
And this time succeeded... The problem came when I realized the original +800GB file was now a 12KB file.
I don't know If I damaged the file or if it was compressed, If so, how do I get back the original size of the file?
I am using a linux SLES 11
When you ran
tar -cvf file.img file.tar
you overwrote file.img, creating a tar file with no contents, even though the tar commmand appeared to fail. So when you swapped the parameters around, your large image file was gone. Sorry but I think you've lost the file.
"man tar" will help you
-c = create new tar file
-x = extract tar file
and compression options are -z -Z -j (-z -Z -y on BSD & MAC)
Related
I have a .tgz file made with tar cvzf tartest.tgz tester/* and if I list the tar with tar --list -f tartest.tgz file, I have the following structure
tester/2017-08-02_131404.png
tester/cfg.pdf
tester/tests/
tester/tests/1.png
tester/tests/2.png
tester/tests/3.png
tester/tests/4.png
tester/tests/5.png
If I compare the tar with the original folder by using tar -df tartest.tgz tester/*, everything ok, no problems, no errors
If I add the file 20171006_183137.png in the tester folder, and retry, I get an error, as expected:
tar: tester/20171006_183137.png: Not found in archive
tar: Exiting with failure status due to previous errors
If I add the file 20171006_183137.png in the tester/tests folder, and retry, I get no error and blank output.
If I add -v option during last test, I just get the list of the files in the tar.
Is there a way to recursive compare tar with original folder and subfolders?
According to this site, tar behaves as intended.
You should note again that while --compare (-d) does cause tar to
report back on files in the archive that do not exist in the file
system, tar will ignore files in the active file system that do not
exist in the archive.
The error you are getting for tar -df tartest.tgz tester/* is indeed an error (!) not a message like »archive and directory differ«. tar does not know how to treat files that are not in the archive.
If you also want to compare the other way around, you could use the method described in this answer (mount or unpack the archive and use diff -r against the original directory).
If you are only interested in a file's existence and not content, access dates, and so on, you could list the file names from the archive and from the original directory and compare them with diff:
diff <(tar -tf tartest.tgz | sort) <(find tester/ | sort)
The command works only if there are no file names with linebreaks in them.
Use diff -y or the comm command for a more readable output.
Background
I downloaded binary for linux 64-bit and I was following several tutorials, each with similar options:
tar -C /usr/local --strip-components 1 -xzf /path/to/node.tar.gz
I always get this error:
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
I've googled and it seems I have manually specified gzip file format via one of these switches. File is actually tar.xz, not tar.gz. It was probably tar.gz in older versions.
I wonder what do all of these options mean and which one's I need?
Is there an auto-detect format option?
This is what running info tar said:
-C, --directory DIR
change to directory DIR
--strip-components=NUMBER
strip NUMBER leading components from file names on extraction
-x, --extract, --get
extract files from an archive
-z, --gzip, --gunzip --ungzip
-f, --file ARCHIVE
use archive file or device ARCHIVE
Questions
I don't understand options -f, --strip-components.
-f - What else can it be but a file? What is "device archive"?
--strip-components - What does --strip-components 1 exactly do here?
I don't see any numbers in the file.
Please provide example of filename which would be affected by --strip-components and explain how.
And what's the idea with installing nodejs on linux?
Just unzip to /usr/local or what else needs to be done?
First, tar is "smart" enough to detect the compression method used in an archive so it isn't necessary to specify -z or -j.
-f - What else can it be but a file? What is "device archive"?
A device archive could be a tape archive attached to your machine in /dev/your_tar
--strip-components - What does --strip-components 1 exactly do
tar xfz /var/www/site/site.gz --strip-components=2
will create /var/site.
I have a large tar archive with many xml files in it. a couple of xml files in this archive are corrupt. How can I extract the good files without the program exiting?
There is a tar file within the gz
tar zxf myFile.gz
tar: Unexpected EOF in archive
tar: rmtlseek not stopped at a record boundary
tar: Error is not recoverable: exiting now
It looks, from the filename, as though you're trying to unpack something that isn't a tar archive. Usually a tar file would have a .tar extension, and if it had been then compressed with gzip, it would be .tar.gz or .tgz.
The command you're running, with the z option to tar, tries to undo gzip compression first, and then untar the resulting archive. But from the .gz extension, it rather looks as though you've got a gzipped file rather than a gzipped tar archive.
The best thing to do is to examine the file to find out what sort of file it is:
file myFile.gz
That will tell you whether it's gzipped or whatever. If it's gzipped, then run
gunzip myFile.gz
That will leave you with myFile without the extension; you can then use
file myFile
to probe it to determine whether it's a tar archive or something else.
mv myFile.gz myFile.tar.gz
gunzip myfile.tar.gz
tar xf myFile.tar
You might try bzip2recover to try recover the bondaries first!
bzip2recover file.bzip
eg from manual:
In case of damage to one member of a .gz file, other members can still be recovered (if the
file: Corrupt input. Use zcat to recover some data.
usage: zcat file > recover
I tried tar with xvfz and -xvfc both didn't work in Cygwin on Windows.
$ tar xvfz sshpass-1.0.5.tar.gz
tar (child): sshpass-1.0.5.tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
Here cmd tar with '-'
$ tar -xvfz sshpass-1.0.5.tar.gz
tar: z: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
Question :
1 . How does tar works with - or without _ ?
Please suggest to execute tar -xvfz sshpass-1.0.5.tar.gz.
tar has 3 types of syntax (according to this ):
long options (--file)
short options (-f)
old options (f)
For the old option syntax, all the letters must follow "tar" and must all fall into a single clump with no spaces. The order of the letters doesn't really matter, so long as the arguments to those letters follow the same order after the clump of options.
This old way of writing tar options can surprise even experienced users. For example, the two commands:
# tar cfz sshpass-1.0.5.tar.gz file
# tar -cfz sshpass-1.0.5.tar.gz file
are quite different. The first example uses ‘sshpass-1.0.5.tar.gz’ as the value for option ‘f’ and recognizes the option ‘z’. The second example, however, uses ‘z’ as the value for option ‘f’ — probably not what was intended.
Old options are kept for compatibility with old versions of tar.
The command with a '-' is equivalent to
tar -czf sshpass-1.0.5.tar.gz file
tar -cf sshpass-1.0.5.tar.gz -z file
tar cf sshpass-1.0.5.tar.gz -z file
Got it, there was a typo error for in file name, corrected and ran. it worked.
$ tar xvfz sshpass-1.05.tar.gz
sshpass-1.05/
sshpass-1.05/COPYING
sshpass-1.05/AUTHORS
sshpass-1.05/aclocal.m4
sshpass-1.05/INSTALL
sshpass-1.05/Makefile.am
sshpass-1.05/configure.ac
sshpass-1.05/install-sh
sshpass-1.05/Makefile.in
sshpass-1.05/sshpass.1
sshpass-1.05/configure
sshpass-1.05/depcomp
sshpass-1.05/README
sshpass-1.05/NEWS
sshpass-1.05/config.h.in
sshpass-1.05/missing
sshpass-1.05/main.c
sshpass-1.05/ChangeLog
Hi I am trying to untar a compressed file on a Solaris server. I run the command
tar xvf 4.56_release.tar.gz
But this reports the following error
tar: directory checksum error
Initially I thought it was a bad download so I re-downloaded the file (actually a different version) and it reports the same error.
Un-compressing and un-tar'ing it on Linux on a Linux server works fine.
Any ideas what I am doing wrong.
The .tar.gz is the hint for what you are doing wrong - you are not uncompressing it first. If your version of tar supports it, you can use the -z flag to specify it is compressed with gzip:
tar -xzvf 4.56_release.tar.gz
Otherwise, you'll have to gunzip it manually:
gunzip -c 4.56_release.tar.gz | tar xvf -
(The reason it works on Linux is probably that is has a newer/different version which automagically detects the compression)
If you have a '.tar.bz2' type of archive file and neither of the above options worked ('-z' is not supported for your version of 'tar'), you can use:
bzip2 -d your_file.tar.bz2
to decompress, then use tar:
tar -xvf your_file.tar
Taken from here: https://www.linuxquestions.org/questions/solaris-opensolaris-20/how-to-unpack-a-tar-bz2-file-654772/
Solaris tar automatically detects if the tar file is compressed or not, as does Linux. But older versions of Solaris and Linux do not do this. For Solaris, I think it needs to be Solaris 11 or greater to automatically detect compressed files. Otherwise use the tar -z option.