I need to compare two folders to find files that are either:
- different size and/or modified date/time
- missing from one
I cannot run diff
against the two folders in my situation. My plan was to use find
on both folders and save the output to two text files and then compare the two text files using diff
.
I assume this would work but need to be sure because my source/target directories are huge and if my test shows no difference, or it doesn't find all the differences, I'd have no way of knowing if it worked or not.
If the two folders are exactly the same I assume it would work. But I question what would happen if one folder had a lot more complex sub-directories/files. Will diff
be able to understand a folder structure printing output?
For example, I will take an inventory of the folder on one day.
$ find /path/to/folder -exec ls -ld {} \; > inventory-20181101.txt
...
I will modify a bunch of things including add, removing, editing files and adding or removing folders and sub-folders. Then another day I will take another inventory.
$ find /path/to/folder -exec ls -ld {} \; > inventory-20181102.txt
...
Then I will diff the two files.
$ diff inventory-20181101.txt inventory-20181102.txt
I assume this will work if there were no changes or the changes were minor, like just modifying files. But what happens if I add 5 levels of nested folders and then 100 files in it, and remove another top-level folder. Will diff
be able to match up the right folders?
diff
works and will it be able to understand differences in folder structures saved in a text file. I will put more detail in my question. Thank you!find
is not guaranteed to list the files in a directory in any particular order. If you run it twice in immediate succession, it will probably give the same results, but, after months of mucking around in the directory tree, things are likely to have changed. Files that have not been modified in any way might be in the same relative order, but I doubt that even that is guaranteed. (2)diff
is notorious for failing to "resync" after large changes, so it may report some unchanged lines as being both deleted and inserted. It will probably not miss any changes.find
anddiff
will not be reliable for me.