How can I compare two directories with sub dirs to see where is the difference?
-
6Operating System please. – Maximus Minimus Feb 09 '10 at 15:22
-
Are you wanting to know if there are different files between the two directories or if the contents of the files are different? – Matt Simmons Feb 09 '10 at 17:19
7 Answers
Under Linux:
$ diff -r /first/directory /second/directory
Under Windows: you'd probably better download and install WinMerge, then
> WinMerge /r c:\first\folder c:\second\folder
M
- 677
- 4
- 15
-
3
-
1Is there an option in the GUI to specify the /r switch without using the command prompt? – Omtara May 07 '13 at 03:31
-
@Omtara, after you have started WinMerge, choose File - Open. In the open dialog, check //Include Subfolders//. If you open WinMerge by selecting two folders in the Windows Explorer, configure Shell integration. Open Edit - Options; navigate to Category //Shell Integration and check //Include subfolders by default//. – R. Schreurs Apr 08 '14 at 15:26
-
+1 for meld, normally I like command line options like diff but being able to visually see the actual different folders of two different directories at a glance in such a visual manner is very useful. Both meld and diff still work just fine on Ubuntu 16.04 and Ubuntu 18.04 for anyone else finding this in 2018. Of course on Windows, WinMerge is a great option. I have heard Meld works on Windows but I have not personally tried it yet. – Ken Apr 22 '18 at 13:45
Diff is normally used to compare two files, but can do much more than that. In diff
he options "r" and "q" make it work recursively and quietly, that is, only mentioning differences, which is just what we are looking for:
diff -rq todo_orig/ todo_backup/
If you also want to see differences for files that may not exist in either directory:
diff -Nrq dir1/ dir2/
You can also use Rsync
and find
. For find
:
find $FOLDER -type f | cut -d/ -f2- | sort > /tmp/file_list_$FOLDER
But files with the same names and in the same subfolders, but with different content, will not be shown in the lists.
If you are a fan of GUI, you may check Meld. It works fine in both windows and linux.
- 121
- 4
Beyond Compare is a good commercial tool, $30 or so. Runs under windows, has an eval version. http://www.scootersoftware.com/
DiffMerge for Windows shows differences including subfolders in a window. There is also a portable version somewhere but a quick search revealed this download: http://www.softpedia.com/get/System/File-Management/SourceGear-DiffMerge.shtml
- 249
- 3
- 10
- 109
- 4
I wrote this using the Compare-Objects cmdlet in Powershell:
#set the directories
$firstdirectory = Read-Host "What is the first directory you wish to compare?" $seconddirectory = Read-Host "What is the second directory you wish to compare?"
#Check if the user wants to compare subdirectories
$recursivesearch = Read-Host "Do you wish to compare subdirectories? Please enter yes or no." If ($recursivesearch -eq "yes")
#get the contents
{ $firstdirectorycontents = @(Get-ChildItem $firstdirectory -Recurse) $seconddirectorycontents = @(Get-ChildItem $seconddirectory -Recurse ) }
else { $firstdirectorycontents = @(Get-ChildItem $firstdirectory) $seconddirectorycontents = @(Get-ChildItem $seconddirectory) }
#compare the objects and handle errors
if ($firstdirectorycontents.Count -eq 0 )
{
Write-Host "No files were found in the first directory, the directories cannot be compared."
}
elseif ($seconddirectorycontents.Count -eq 0)
{
Write-Host "No files were found in the second directory, the directories cannot be compared."
}
else
{
try
{
Compare-Object -ReferenceObject $firstdirectorycontents -DifferenceObject $seconddirectorycontents
}
catch {"Another error occured."} }
- 1,210
- 3
- 14
- 24