Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to create a .tar file in Cygwin:

find . > tmpfilelist
tar -cf tmp.tar -T tmpfilelist

but when I open tmp.tar in Windows with 7-Zip there are four instances of each file:

Name              Size            Link
.gitignore        62
.gitignore        0               path/to/.gitignore
.gitignore        0               path/to/.gitignore
.gitignore        0               path/to/.gitignore

and when I extract the tar to its own folder I am prompted to overwrite each file three times. Additionally, viewing the extracted folder's properties in Explorer shows a size of 0 bytes.

Is it possible to create a .tar file in Cygwin that will behave in Windows? Just to clarify, I'm only using the .gitignore files as an example; the issue seems to be with all files.

Edit:

$ tar -tvf tmp.tar | grep -i "link to" | grep -i ".gitignore" | sort | head -n20
hrw-r--r-- user/None        0 2011-07-06 11:27 path/to/.gitignore link to path/to/.gitignore
hrw-r--r-- user/None        0 2011-07-06 11:27 path/to/.gitignore link to path/to/.gitignore
hrw-r--r-- user/None        0 2011-07-06 11:27 path/to/.gitignore link to path/to/.gitignore
hrw-r--r-- user/None        0 2011-09-29 15:40 path/to/other/.gitignore link to path/to/other/.gitignore
hrw-r--r-- user/None        0 2011-09-29 15:40 path/to/other/.gitignore link to path/to/other/.gitignore
hrw-r--r-- user/None        0 2011-09-29 15:40 path/to/other/.gitignore link to path/to/other/.gitignore
...

.

$ grep -i ".gitignore" tmpfilelist | sort | head -n20
path/to/.gitignore
path/to/other/.gitignore
...

Cygwin's tar is showing the same listing, but the tmpfilelist does not appear to have these extra links. So I guess the real question is how to make a nicely formed tar file in Cygwin? I'm not sure if they're relevant or how to apply tar's --dereference and --hard-dereference options.

Edit: As far as I know, 7z doesn't preserve directory structures when given a list of files without specifying a root and there is no common root for some of the files in my list (the list will eventually be aggregate for multiple find executions).

share|improve this question
    
Have you tried 7zip? 7-Zip allows you to double click the file inside its file manager and explore it, so you can double click the tar.bz and get the tar, and double click again to get the files inside. –  AlanTuring Oct 10 '12 at 16:25
    
@AlanTuring: I'm not creating a tar.bz, I'm only using tar -cf. –  wes Oct 10 '12 at 16:38
    
What do you get if your execute tar -tvf tmp.tar? Also, what is listed if you print out file tmpfilelist? –  HeatfanJohn Oct 10 '12 at 16:40
    
pretty sure 7zip has support for every archive under the sun. –  AlanTuring Oct 10 '12 at 16:44
add comment

1 Answer

up vote 2 down vote accepted

One problem may be that find . > tmpfilelist lists both files and directories.

tar parses tmpfilelist and adds any listed directory to the tar file with its contents.

tar also adds any file listed in tmpfilelist, but those files were already added by tar when it processed the directories. The result is that files are included more than once (eventually many times, if files reside deep in the directory structure).

You should use:

find . ! -type d > tmpfilelist

to generate a list of filesystem objects with the exception of directories.

As for the symlinks you mention, it's a mistery to me how they end up being part of the tar file.

EDIT: The symlinks may already exist. List them with find . -type l.

share|improve this answer
    
Excluding directories in the find seems to have solved all my problems. I didn't realize tar had that particular behavior. Thanks! –  wes Oct 10 '12 at 21:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.