cygwin extracting to another directory - linux

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

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.

How tar xvfz works in cygwin?

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

Script don't extract tar

I have this script shell, it extract and install libpcap library
#!/bin/sh
PATH=/usr/src
wget=/usr/bin/wget
tar=/bin/tar
echo "###############"
echo "INSTALL LIBPCAP"
echo "###############"
$tar -xvf libpcap-1.3.0.tar.gz
cd libpcap-1.3.0
./configure --prefix=/usr
make && make install
When I execute it , I have this error
tar (child): gzip: Cannot exec: No such file or directory
tar (child): Error is not recoverable: exiting now
/bin/tar: Child returned status 2
/bin/tar: Error is not recoverable: exiting now
./install.sh: 14: cd: can't cd to libpcap-1.3.0
You've changed PATH to /usr/src so when tar tries to exec gzip, it cannot find it because it only looks in /usr/src. You'll need to add the location of gzip to PATH (and the location of every tool that the configure script is going to call, as well as make), or call it explicitly instead of letting tar call it, or (best choice), don't modify PATH. If you insist on changing PATH, try PATH=/usr/src:/usr/sbin:/usr/bin:/sbin:/bin or PATH=/usr/src:$PATH, but really it's best to leave it alone and really odd to put a directory named src into it.
Incase if you want /usr/src added to PATH variable then the better approach will be as
PATH="$PATH:/usr/src"
To make your script run from any directory path use a separate variable which holds the absolute path of the source file path like file_path variable which is used in the below script.
#!/bin/sh
PATH="$PATH:/usr/src"
wget=/usr/bin/wget
tar=/bin/tar
file_path="/path/to/source-files"
echo "###############"
echo "INSTALL LIBPCAP"
echo "###############"
$tar -xvf $file_path/libpcap-1.3.0.tar.gz
cd $file_path/libpcap-1.3.0
./configure --prefix=/usr
make && make install
When dealing with gzipped tar, you should explicitly pass the option -z, so your code should be something like:
$tar -xzvf libpcap-1.3.0.tar.gz

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)

How to extract this .tgz file in cygwin

I have install cygwin and want to install a tgz file. I typed following command:
$tar xvfz tidy_src.tgz
Error occurs:
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error is not recoverable: exiting now
Then I type following command to check;
$file tidy_src.tgz
It shows it's a ASCII text
So I continue type:
$tar xvf tidy_src.tgz
Still doesn't work.
Anyone can give some help?
You can download this free-virus file at http://tidy.sourceforge.net/src/tidy_src.tgz
untarring a gzipped file that you have made yourself from known content with the same command.
if that works then you confirm that the archive is corrupt.

Resources