Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

With diff -r I can do this task, however it takes so long because diff checks file's content.

I want something that determine that two files are the same regarding of their size, last modified, etc. But no checking bit by bit the file (for example a video takes sooo long)

Is there any other way?

share|improve this question
add comment

4 Answers

Use the -q (--brief) option with diff -r (diff -qr). From the info page for GNU diff:

1.6 Summarizing Which Files Differ

When you only want to find out whether files are different, and you don't care what the differences are, you can use the summary output format. In this format, instead of showing the differences between the files, diff' simply reports whether files differ. The--brief' (`-q') option selects this output format.

This format is especially useful when comparing the contents of two directories. It is also much faster than doing the normal line by line comparisons, because `diff' can stop analyzing the files as soon as it knows that there are any differences.

This will not compare line by line, but rather the file as a whole, which greatly speeds up the processor (what' you're looking for).

share|improve this answer
    
The problem of - q is that it compares normal and when finds a difference stops (if were normal mode it keeps comparing), so if huge files are the same it will last a lot. –  yzT Dec 24 '12 at 18:34
add comment

Here's a quick python script that will check that the filenames, mtimes, and file sizes are all the same:

import os
import sys

def getStats(path):
    for pathname, dirnames, filenames in os.walk(path):
        for filename in ( os.path.join(pathname, x) for x in filenames ):
            stat = os.stat(filename)
            yield filename[len(path):], stat.st_mtime, stat.st_size

sys.exit(tuple(getStats(sys.argv[1])) != tuple(getStats(sys.argv[2])))
share|improve this answer
add comment

If you'd like to compare only a structure and some basic info about files, you can try something like this:

diff <(ls -laR $DIR1) <(ls -laR $DIR2)

I didn't test it, so any edits are welcome :)

share|improve this answer
1  
This won't work as the directory names themselves will also be in the results. –  Chris Down Dec 24 '12 at 19:05
    
what if we will exclude first column with directory names? like <(ls -laR | awk '{$1=""; print}') –  Volodymyr Dec 24 '12 at 19:23
    
Not all lines are directory names, so that won't work properly. –  Chris Down Dec 24 '12 at 20:19
add comment

We built a tool that runs diff algorithms between multiple servers. It tells you if the files metadata like date, size, etc are different. It's in free beta right now, http://metaforsoftware.com, and we plan to always have a free version. Hope it can help you. (Full disclosure: I'm a co-founder)

share|improve this answer
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.