Answers:
在Linux下:
$ diff -r /first/directory /second/directory
在Windows下:最好下载并安装WinMerge,然后
> WinMerge /r c:\first\folder c:\second\folder
中号
Beyond Compare是一款不错的商业工具,大约30美元。在Windows下运行,具有评估版本。http://www.scootersoftware.com/
Diff通常用于比较两个文件,但可以做的更多。在diff
选项中,“ r”和“ q”使其递归且安静地工作,也就是说,仅提及差异,这正是我们要寻找的:
diff -rq todo_orig/ todo_backup/
如果您还想查看两个目录中可能不存在的文件的差异,请执行以下操作:
diff -Nrq dir1/ dir2/
您也可以使用Rsync
和find
。对于find
:
find $FOLDER -type f | cut -d/ -f2- | sort > /tmp/file_list_$FOLDER
但是具有相同名称和相同子文件夹但具有不同内容的文件将不会显示在列表中。
如果您是GUI的粉丝,则可以查看Meld。它在Windows和Linux中都可以正常工作。
Windows的DiffMerge显示差异,包括窗口中的子文件夹。某个地方也有便携式版本,但快速搜索显示了此下载内容:http : //www.softpedia.com/get/System/File-Management/SourceGear-DiffMerge.shtml
我是在Powershell中使用Compare-Objects cmdlet编写的:
#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."} }