linuxcommand-linediff

How to diff and only show filenames of files that differ?


I'm looking to run a Linux command that will recursively compare two directories and output only the file names of what is different. This includes anything that is present in one directory and not the other or vice versa, and text differences.


Solution

  • From the diff man page:

    -q   Report only whether the files differ, not the details of the differences.
    -r   When comparing directories, recursively compare any subdirectories found.

    Example command:

    diff -qr dir1 dir2
    

    Example output (depends on locale):

    $ ls dir1 dir2
    dir1:
    same-file  different  only-1
    
    dir2:
    same-file  different  only-2
    $ diff -qr dir1 dir2
    Files dir1/different and dir2/different differ
    Only in dir1: only-1
    Only in dir2: only-2