Given two directory trees, how can I find out which files differ by content?
Try:
diff --brief --recursive dir1/ dir2/
Or alternatively, with the short flags -qr
:
diff -qr dir1/ dir2/
If you also want to see differences for files that may not exist in either directory:
diff --brief --recursive --new-file dir1/ dir2/ # with long options
diff -qrN dir1/ dir2/ # with short flag aliases
Given two directory trees how to find which filenames are the same, considering only filenames satisfying a condition?
This is untested, but I'd try something like:
comm -12 <(cd dir1 && ls E*) <(cd dir2 && ls E*)
Basic idea:
Generate a list of filenames in
dir1
that satisfy our condition. This can be done withls E*
because we're only dealing with a flat list of files. For subdirectories and recursion we'd usefind
instead (e.g.find . -name 'E*' -type f
).Put the filenames in a canonical order (e.g. by sorting them). We don't have to do anything here because
E*
expands in sorted order anyway. Withfind
we might have to pipe the output intosort
first.Do the same thing to
dir2
.Only output lines that are common to both lists, which can be done with
comm -12
.comm
expects to be passed two filenames on the command line, so we use the<( ... )
bash feature to spawn a subprocess and connect its output to a named pipe; the name of the pipe can then be given tocomm
.
given two directory trees how to find which files are the same?
Well i found the answer myself. I had tried it before, but I thought it did not work.
diff -srq dir1/ dir2/ | grep identical
What -srq means? From diff --help :
-s --report-identical-files Report when two files are the same.
-r --recursive Recursively compare any subdirectories found.
-q --brief Output only whether files differ.
Diff files present in two different directories
You can use the diff
command for that:
diff -bur folder1/ folder2/
This will output a recursive diff that ignore spaces, with a unified context:
- b flag means ignoring whitespace
- u flag means a unified context (3 lines before and after)
- r flag means recursive
How do I compare two source trees in Linux?
You can try Meld. It is a wonderful visual diff tool ;-)
Related Topics
How to Detect Invalid Utf8 Unicode/Binary in a Text File
What Killed My Process and Why
Print a File, Skipping the First X Lines, in Bash
Kdevtmpfsi Using the Entire Cpu
Multiline Bash Command in Jenkins Pipeline
How to Concatenate Multiple Lines of Output to One Line
Change the X-Frame-Options to Allow All Domains
Remove a Specific Character Using Awk or Sed
How to Simulate Just One Enter in Command Line After Executing a Jar File
Error:13 - Permission Denied Android Studio
Curl Command to Repeat Url Request
Format and Then Convert Txt to CSV Using Shell Script and Awk
How to Access Physical Addresses from User Space in Linux
Redirect Stderr/Stdout of a Process After It's Been Started, Using Command Line