Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Diff between two entire directories that contain source and output the result in a textfile

Tags:

bash

diff

I have two directories that contain directories and source files. One directory contains the modified source code and the other one is unmodified source code. And I want to see what source code was modified and see the modified part of the code. And I also want to output the result to a single text file.

I know I have to use the diff tool but I'm not sure what options should I use. Do I need to create a script for this, or is there a one line command to do the task?

like image 251
domlao Avatar asked Feb 07 '12 00:02

domlao


People also ask

How can I find the difference between two folders?

To do so, click “View” in the top bar, and then untick “Show identical items” by clicking on it. Click on the “Select Files or Folders” tab in the far left, to start a new comparison. Each comparison you run opens in a new tab.

How do I compare two directories in UNIX?

Use the dircmp command to compare two directories specified by the Directory1 and Directory2 parameters and write information about their contents to standard output. First, the dircmp command compares the file names in each directory.

How do I compare two directories in Ubuntu?

Using Meld Visual Diff and Merge Tool Click on directory comparison and move to the next interface. Select the directories you want to compare, note that you can add a third directory by checking the option “3-way Comparison”. Once you selected the directories, click on “Compare”.


1 Answers

You might want to do something like

diff -rw directory1 directory2 > diff.txt

where -r makes it recursive (so all sub-directories are scanned, too), -w is for ignoring all white-space (e.g., stray spaces or tabs somebody inserted), and > diff.txt redirects your output to the file diff.txt. More options can be found in the man page:

  • man diff
like image 194
Alex P. Avatar answered Sep 30 '22 16:09

Alex P.