I created a file named me.txt with text

This is dummy text

Then I made a TAR out of it and named me.txt.tar.

Now after a minute I again created a file with exactly same name and the text (basically I just did touch me.txt), then made TAR out of it called me2.txt.tar.

Technically both the tars have same file with same file contents but time of creation of file me.txt is different. But the diff tool is saying:

Binary files me.txt.tar and me2.txt.tar differ

This is because of reason of timestamp difference of file creation. But I just want to compare the contents of file and need to ignore the timestamp & hence I expect no output from the diff.

Please help me to ignore the timestamp of the files inside a TAR or JAR etc. as my concern is towards the contents of files.

  • The commands I used are :
    $ echo "This is dummy text" > me.txt
    $ tar -cvf me.txt.tar me.txt
    (After 1 minute or so..)
    $ touch me.txt 
    $ tar -cvf me2.txt.tar me.txt
    $ diff me.txt.tar me2.txt.tar
  • output:
    Binary files me.txt.tar and me2.txt.tar differ

Even diffoscope gives similar output.


1 Answer 1


Since you want to compare the contents of the files in your archives, and not the metadata in the archives themselves, you should compare the contents. Assuming the files are stored in the same order in all archives,

diff -u <(tar xOf me.txt.tar) <(tar xOf me2.txt.tar)

For JARs, you’d use unzip:

diff -u <(unzip -c file1.jar) <(unzip -c file2.jar)
  • Hey Stephan, Thanks for the answer. The above method is working fine for tars i.e., 1st command works!! But the second command i.e., on jars, is not working.. (Output says "binary files differ" but they are actually not) Sep 6, 2021 at 10:29
  • What does diffoscope --exclude-directory-metadata=recursive says is the difference between your JARs? Sep 6, 2021 at 11:31
  • @stephan this option is not working!! Sep 7, 2021 at 8:14
  • My name is Stephen, not Stephan. What do you mean by “is not working”? Does it produce an error message? Sep 7, 2021 at 8:33
  • It says - ignored explicit argument 'recursive' & if I remove recursive, its still giving diffoscope output while it should not Sep 7, 2021 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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