linux diff: is there a way to list differences by when the files were last modified?

3

In the Linux terminal, I'm using

diff --recursive --brief dir1 dir2

A couple of weeks ago, dir1 and dir2 were identical, but they have both been modified since then. I would like to order to outputs by the date of the last modification for the files in dir2 (or dir1, or whichever is more recent, or the time at which they began to differ).

I looked at the diff options and there doesn't seem to be a built in way to do any of these. Does anyone know a way?

capybaralet

Posted 2013-05-28T19:32:23.097

Reputation: 159

maybe if you use find, then sort, then xargs? – Szocske – 2013-05-28T19:37:52.993

1I think it's time to put those directories under version control. (See: git) – michael – 2013-09-17T08:18:52.480

Answers

1

No, of all diff options, there isn't a built in way to do any of the things your required. You have to coin your own solution.

This would be a fairly simple and straightforward solution to start with:

find /path/to/dir1  /path/to/dir2 -printf "%TY-%Tm-%Td %TH:%TM %p\n" | sort -r

what it gives you is a list of files in reverse-chronological order.

  1. All the files that is newer than that a couple of weeks ago when dir1 and dir2 were identical are modified.
  2. The modified file that comes on the top of the list is modified more recently. E.g., if fileN in dir1 shows up higher than dir2, then fileN in dir1 is newer.

Is this good enough?

xpt

Posted 2013-05-28T19:32:23.097

Reputation: 5 548