Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

diff to output only the file names

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.

like image 693
barfoon Avatar asked Oct 04 '22 20:10

barfoon


People also ask

What does diff output if the files are the same?

The diff command can display the output in several formats with the normal, context, and unified format being the most common ones. The output includes information about which lines in the files must be changed so that they become identical. If the files match, no output is produced.

How do I list filenames only in Linux?

How to make ls display only filenames and file sizes in output. If you want the ls command output to only contain file/directory names and their respective sizes, then you can do that using the -h option in combination with -l/-s command line option.

What is in diff output?

You can use diff to merge two files of C source code. The output of diff in this format contains all the lines of both files. Lines common to both files are output just once; the differing parts are separated by the C preprocessor directives #ifdef name or #ifndef name , #else , and #endif .

What are diff files?

A DIFF file is a single file showing the differences between one or more text or source files. It is created by Mercurial, a control management tool for developers to obtain differences between files and apply the patches.


2 Answers

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
like image 446
John Kugelman Avatar answered Oct 16 '22 19:10

John Kugelman


You can also use rsync

rsync -rv --size-only --dry-run /my/source/ /my/dest/ > diff.out
like image 40
boksiora Avatar answered Oct 16 '22 19:10

boksiora