1

I want to use tar to preserve only file names, file contents, and the executable bit for the owner (and ignore the executable bit for group and other). The command I have come up with is

tar -cf <name>.tar --numeric-owner --owner=0 --group=0 --mode="go-rwx,u-rw" <files>

I would like the output <name>.tar not to change unless I change the file name, file contents, or owner's executable bit in one or more of <files>. Assume that the <files> are in sorted order by name.

Will the command that I have written do that?

Tom Ellis
  • 9,224
  • 1
  • 29
  • 54
  • What exactly does not work with the command that you have given? – Stefan Kögl Aug 17 '17 at 12:09
  • The command works fine. I'm wondering whether it always creates the exact same file when the input filenames, file contents, and owner execute bit are the same. – Tom Ellis Aug 17 '17 at 12:15
  • Have you tried to make some changes to the files, and then comparing the checksums of the reslting tar file? – Stefan Kögl Aug 17 '17 at 12:23
  • 1
    I know that if I change the file the output will change! I asking whether there are *other* things I can change that will cause the output to change. One such thing that I now realise that I left off is the `mtime`. I'm asking if there are others. – Tom Ellis Aug 17 '17 at 12:54
  • OK, I see. I would recommend to explicitly state that in your initial question. – Stefan Kögl Aug 17 '17 at 12:57
  • Which bit of my question should I change? I hoped I had made it clear. – Tom Ellis Aug 17 '17 at 12:58
  • @TomEllis Have you managed to find the solution? Also, do you know how to do in the reverse direction, that is, given any tar archive, how do you extract only the file name, contents and executable bit, for every entry in the archive? – mljrg Sep 21 '17 at 09:40
  • @mljrg I wrote up a complete summary of my findings here http://h2.jaguarpaw.co.uk/posts/reproducible-tar/ It answers the Y that this question was an X to, about reproducibility. I hope that helps you. – Tom Ellis Sep 21 '17 at 17:20
  • 1
    @TomEllis Maybe you will find [this question](https://stackoverflow.com/questions/46321878/how-to-verify-if-the-content-of-two-docker-images-is-exactly-the-same) interesting and useful. – mljrg Sep 21 '17 at 18:10

0 Answers0