2

I have a local working folder which mirrors part of a web server’s public folder. I usually work in the local copy and then auto-upload files to the server when saving. Trouble is, I’ve realised lately that a lot of files in my local files appear to be out of date, so whenever I save and upload a file, I’m potentially overwriting a newer version. This is obviously problematic, so I’d like to get all the out-of-date local files up to date.

The best way I can think of to do this is to download the entire public folder as it is and compare each file with my local copy, going manually through files with differences (by comparing them in Visual Studio Code). The public server folder has about 5GB of extra stuff that I don’t need (or want) in my local working folder, though, so I’d have to filter out the unwanted stuff first.

In other words, I’m looking for a way (GUI or terminal) to do the following:

  • Give two top-level directories as input
  • Iterate recursively through both directories and pick out files which exist in both (in the same relative location)
  • Compare each set of matched files and list the ones where the two files are not identical

Is there some reasonably non-complex way of doing this?

3 Answers 3

4

While I'm a big proponent of utilizing built in tools (+1 for nohillside's answer) rather than searching for the nearest app, from time to time I do find really invaluable applications. In this case, I found a graphical differencing and merging application called Meld.

Meld is a visual diff and merge tool targeted at developers. Meld helps you compare files, directories, and version controlled projects. It provides two- and three-way comparison of both files and directories, and has support for many popular version control systems.

Meld Screenshot

Meld is probably overkill for what you're looking to do, but not so much that it makes the software cumbersome to use. The best part is that it's free (as in beer).

4
  • Can you add clarification regarding any affiliation (or not) with the app? Thanks.
    – Nimesh Neema
    Commented Feb 18, 2020 at 4:24
  • @NimeshNeema, the words “I found...” directly imply I have nothing to do with them other than “finding them” and now recommending them.
    – Allan
    Commented Feb 18, 2020 at 4:41
  • My bad for not paying attention when reading. I found the tool useful too. Thanks for sharing.
    – Nimesh Neema
    Commented Feb 18, 2020 at 4:43
  • 1
    Took a while for me to get the time to actually do something about this, but I’ve just tried out Meld for this, and it works an absolute charm – straightforward comparison and easy overview of the actual changes straight from the diff view. Excellent! Commented Feb 22, 2020 at 22:24
8

You can use diff for this after downloading the public folder:

diff -q -r working-folder public-folder

It will give you the list of files which are different, omit -q to also show a list of the actual differences.

To supress the listing of files only available in public-folder you can easily filter them via grep:

diff -q -r working-folder public-folder | grep -v '^Only in public-folder'

(make sure to replace the public-folder part with the real name in both occurances)

5
  • But will this not also list all the files that exist in public-folder but not in working-folder? That’s what I’m trying to avoid, because that would probably match nearly 50,000 files. Commented Feb 17, 2020 at 15:47
  • @JanusBahsJacquet Ah, missed that. See edit. Not elegant, but as a one-off exercise it should work.
    – nohillside
    Commented Feb 17, 2020 at 15:51
  • Ah, clever, didn’t think of piping it through like that! This is indeed a one-off, so elegance is not required. But… does “Only in” do anything in grep? Is that some sort of special grep syntax I’ve never seen before? Commented Feb 17, 2020 at 15:54
  • @JanusBahsJacquet It sure looks that way :-) But no, it's just the pattern to grep for, the -v inverts the search so only lines not starting with "Only in public-folder" will pass through.
    – nohillside
    Commented Feb 17, 2020 at 15:56
  • Ah, so diff returns a line that starts with “Only in public-folder” if the file appears only there (even with -q) – that makes much more sense! This should work quite well, then. :-) Commented Feb 17, 2020 at 16:01
0

Try DirEqual. It has very intuitive interface.

2
  • Could you provide a link to what you mean by "DirEqual"?
    – Glyph
    Commented Jul 14, 2021 at 20:50
  • google.com/search?q=direqual but I've just found it's for Mac only (no Windows version).
    – stapoz
    Commented Jul 15, 2021 at 21:15

You must log in to answer this question.

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