How tar xvfz works in cygwin? - linux

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

Related

Files with Hyphen at Beginning of Name

I have a bunch of files such as this --4gqARaEJE_0.000.wav.gz. How do I decompress them? Executing tar -xz --4gqARaEJE_0.000.wav.gz returns the error tar: unrecognized option '--4gqARaEJE_0.000.wav.gz'. Gzip returns the same error. I take it the hyphens are causing the error, but don't know the workaround.
I tried changing the file names to remove the hyphens, but that gives the same error. I also tried \ prior to the file name, but no luck there either. How do you handle this kind of thing?
I've tried a small example on my server.
With wget https://sourceforge.net/projects/od1n/files/samples.tar.gz/download I've downloaded a random sample file and saved it. File name was download initially.
I tried this:
root#server [~/stackoverflow]# mv download --download.tar.gz
mv: unrecognized option '--download.tar.gz'
Try `mv --help' for more information.
As expected, it didn't work but adding a -- did help.
root#server [~/stackoverflow]# mv -- download --download.tar.gz
root#server [~/stackoverflow]# ls
./ ../ --download.tar.gz
Now our file name is --download.tar.gz, to extract it I used following command.
tar -xvzf -- --download.tar.gz
This still fails.
tar: unrecognized option '--download.tar.gz'
However specifiying folder location did work as intended.
root#server [~/stackoverflow]# tar -xvzf ./--download.tar.gz
samples/
samples/modifiedSheppLogan_256x256.smp
samples/fmri_64x64.smp
samples/qualityPhantom_64x64.smp
samples/brain_64x64.smp
samples/brain_64x64x5.smp
samples/qualityPhantom_64x64x5.smp
samples/modifiedSheppLogan_64x64.smp
samples/brain_256x256.smp
samples/qualityPhantom_256x256.smp
samples/brain_128x128x5.smp
samples/fmri_128x128.smp
samples/modifiedSheppLogan_128x128.smp
samples/qualityPhantom_128x128x5.smp
samples/brain_256x256x5.smp
samples/point_spread_function.smp
samples/qualityPhantom_256x256x5.smp
samples/brain_128x128.smp
samples/qualityPhantom_128x128.smp
samples/frequency_dist.smp
root#server [~/stackoverflow]# ls
./ ../ --download.tar.gz samples/
In your case file might've been corrupted or the extension could be wrong.

Tar recursive compare with original folder

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.

Which tar options do I need to install node from binary on linux?

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.

cygwin extracting to another directory

I have a file, in Windows, called php_0.27.tar.gz and want to extract it to C:\Program Files\PHP\script through Cygwin using this command:
tar -xf php_0.27.tar.gz -C /Program Files/PHP/script
But I got an error saying:
tar: Files: Not found in archive
I tried this command too:
tar -xf php_.tar.gz --directory /Program Files/PHP/script
But I got an other error saying:
tar: php_0.27.tar.gz: Cannot open: No such file or directory
So I tried:
tar -xf php_.tar.gz --directory C:/Program Files/PHP/script
But I failed and now I am stuck. I need help
The space in the directory name Program Files is the source of the error ; putting the whole path to directory between quotes like this "C:/Program Files/PHP/script" solve the problem

How to untar a .img file?

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)

Resources