I'm currently using a script to backup files on my computer.

In a nutshell, it works like this:

rsync --link-dest=$FOLDER/current $SOURCE $DESTINATION

However, I think that my script may be duplicating some files rather than hard linking them. I would like to verify which files are (or aren't) detected as duplicates. I know that the file has been hardlinked correctly of the two files share the same inode.

How can I do a diff of two folders by inodes?

cd path1
find . -type f -exec ls -i {} + | sort -k2 > ~/path1.lst
cd path2
find . -type f -exec ls -i {} + | sort -k2 > ~/path2.lst
cd ~
diff -U0 path1.lst path2.lst

If i understand correctly, your backup files are stored with duplicates. I think you can add to script date stamp or/and checksum, like md5sum. For example:

DESTINATION="(date +%F-%H-%M).foo-files"

### Checking md5 hash ###

z=`echo $x | /usr/bin/md5sum`
a=`echo $y | /usr/bin/md5sum`
if [ "$z" = "$a" ];then
        echo '=-=-=-Stuff_duplicate-=-=-='
        . . .

Notice: MD5-hash will changed if only one or more symbols are differents in two files.

Good luck! =)

  • I could take the MD5 of each file, but that wouldn't be sufficient. I don't want to verify that the files have the same content, I want to verify that the files are the same file (e.g. both files have the same inode value). Hence, I want to run a diff comparing by inodes – NT3RP Dec 7 '12 at 7:18

Not sure if I understand correctly what you mean but when you mention hardlink I hope you mean hardlink between the backups and not original and backup files.

You can find which files have the same inode with find.

find dest_dir -samefile orig_dir/file

this command will provide you with a file list that matches the same inode as the original one.

If you will put this inside a loop you can do something similar to

for i in `ls orig_dir`
        result=`find dir2/ -samefile dir1/firstfile`
        if [ result  != "" ]
                echo "Duplicate: " $i

This will print all the files that are hardlink between original directory and destination directory by inode. Notice that I'm performing the if based on the output as find always returns true using this flags. from the man page.

All options always return true. Except for -daystart, -follow and -regextype


You can use the -v (verbose) and -n (dry run) parameters to the rsync command to simulate and view file changes.

rsync -van src_dir/ dest_dir/ --delete 

Note that rsync prior to 1.0.1 does not work well when the file exists in both destination dir and link-dest dir.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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