Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Diff a filesystem structure? [closed]

In OSX or Linux, how can I easily compare a path Foo and a path Bar and get a list of ALL files and folders that are different between them?

It would also be handy to get a number of KB of total difference between the two paths.

My use case is that I want to verify that path A was completely copied to path B, and I'm certain that there will be very small differences due to different capabilities of the underlying FS types, so I need a tool/script that will do more than just tell me "yes" or "no".

like image 968
themirror Avatar asked Sep 03 '25 09:09

themirror


2 Answers

Since you want to copy files from folder A to folder B, you know that folder B might be missing files (not folder A), you could then loop over all files in folder A and check if they have the same size in folder B. Something like

#!/bin/bash

for file in `ls A`
do
    # check if file exists
    if [ -e B/"${file}" ]
    then
        fileSize1=`stat -c%s A/"${file}"`
        fileSize2=`stat -c%s B/"${file}"`
        if [ ${fileSize1} -ne ${fileSize2} ]
        then
            echo "The files ${file} have not the same size."
        fi
    else
        echo "The file ${file} does not exist."
    fi
done

Of course you have to be careful with subdirectories.

like image 135
pfnuesel Avatar answered Sep 04 '25 23:09

pfnuesel


Option 1

You can simply use diff

diff -qr dir1 dir2

You can also play with --exclude and the many other options.

Option 2

You can use another GUI tool like Meld (or maybe Midnight-Commander on console)

Sources: the 1st 2 answers i found in duckduckgo

  • https://www.tecmint.com/compare-find-difference-between-two-directories-in-linux/
  • https://www.baeldung.com/linux/compare-two-directories

Related:

  • https://unix.stackexchange.com/questions/524074/compare-two-folders-for-missing-files
like image 21
Nande Avatar answered Sep 04 '25 23:09

Nande