3

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).

4
  • 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.
    – pneumatics
    Commented Oct 10, 2012 at 16:25
  • @AlanTuring: I'm not creating a tar.bz, I'm only using tar -cf.
    – wes
    Commented Oct 10, 2012 at 16:38
  • What do you get if your execute tar -tvf tmp.tar? Also, what is listed if you print out file tmpfilelist? Commented Oct 10, 2012 at 16:40
  • pretty sure 7zip has support for every archive under the sun.
    – pneumatics
    Commented Oct 10, 2012 at 16:44

1 Answer 1

2

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.

1
  • Excluding directories in the find seems to have solved all my problems. I didn't realize tar had that particular behavior. Thanks!
    – wes
    Commented Oct 10, 2012 at 21:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .