Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I compare two directories with sub dirs to see where is the difference?

share|improve this question
Operating System please. – Le Comte du Merde-fou Feb 9 '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 9 '10 at 17:19
up vote 17 down vote accepted

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


share|improve this answer
I use diff -qrl now... – alexus Aug 10 '11 at 19:28
Is there an option in the GUI to specify the /r switch without using the command prompt? – Omtara May 7 '13 at 3: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 8 '14 at 15:26

Beyond Compare is a good commercial tool, $30 or so. Runs under windows, has an eval version.

share|improve this answer

I used meld on Ubuntu - it has a good directory comparison option.

share|improve this answer

On Windows, I believe windiff does it, however Winmerge is my tool of choice for this job. It's open source and does a very neat job of comparing two sets of directory trees.

edit: oops, was beaten to it by Marius

share|improve this answer

DiffMerge for Windows shows differences including subfolders in a window. There is also a portable version somewhere but a quick search revealed this download:

share|improve this answer

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."
            Compare-Object -ReferenceObject $firstdirectorycontents -DifferenceObject $seconddirectorycontents 

        catch {"Another error occured."} }
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.