AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 111151
Accepted
alexus
alexus
Asked: 2010-02-10 07:18:03 +0800 CST2010-02-10 07:18:03 +0800 CST 2010-02-10 07:18:03 +0800 CST

如何比较两个目录(包括子目录)的差异?

  • 772

如何将两个目录与​​子目录进行比较以查看差异在哪里?

filesystems diff
  • 7 7 个回答
  • 32173 Views

7 个回答

  • Voted
  1. Best Answer
    MariusPontmercy
    2010-02-10T07:40:18+08:002010-02-10T07:40:18+08:00

    在 Linux 下:

    $ diff -r /first/directory /second/directory
    

    在 Windows 下:你可能最好下载并安装 WinMerge,然后

    > WinMerge /r c:\first\folder c:\second\folder
    

    米

    • 22
  2. DNayak
    2013-06-21T02:48:55+08:002013-06-21T02:48:55+08:00

    我在 Ubuntu 上使用了meld——它有一个很好的目录比较选项。

    • 2
  3. Fábio
    2017-11-28T11:53:54+08:002017-11-28T11:53:54+08:00

    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 中都可以正常工作。

    • 2
  4. Johnny D
    2010-02-10T08:36:05+08:002010-02-10T08:36:05+08:00

    Beyond Compare 是一个很好的商业工具,30 美元左右。在 windows 下运行,有一个 eval 版本。http://www.scootersoftware.com/

    • 1
  5. Bryan
    2010-02-10T08:40:21+08:002010-02-10T08:40:21+08:00

    在 Windows 上,我相信 windiff 可以做到这一点,但Winmerge是我完成这项工作的首选工具。它是开源的,在比较两组目录树方面做得非常好。

    编辑:哎呀,被马吕斯打败了

    • 1
  6. GHad
    2010-02-10T08:42:42+08:002010-02-10T08:42:42+08:00

    DiffMerge for Windows 显示差异,包括窗口中的子文件夹。还有一个便携式版本,但快速搜索显示此下载: http: //www.softpedia.com/get/System/File-Management/SourceGear-DiffMerge.shtml

    • 0
  7. Davidw
    2014-08-14T17:42:33+08:002014-08-14T17:42:33+08:00

    我使用 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."} }
    
    • 0

相关问题

  • 我如何知道 AIX 中磁盘上的文件系统是什么?

  • 控制 UNIX 目录内容用户组所有权

  • 在 Ubuntu 上将 Windows 磁盘分区与 Linux 分区合并

  • 在 VMPlayer 上 Windows 和 Linux 之间共享目录的最佳方式

  • md5sum 重复为同一台机器上的同一文件提供不同的校验和

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    从 IP 地址解析主机名

    • 8 个回答
  • Marko Smith

    如何按大小对 du -h 输出进行排序

    • 30 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    MikeN 在 Nginx 中,如何在维护子域的同时将所有 http 请求重写为 https? 2009-09-22 06:04:43 +0800 CST
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    0x89 bash中的双方括号和单方括号有什么区别? 2009-08-10 13:11:51 +0800 CST
  • Martin Hope
    Kyle Brandt IPv4 子网如何工作? 2009-08-05 06:05:31 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve