Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

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"

#!/bin/sh
### Checking md5 hash ###

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

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

Good luck! =)

share|improve this answer
    
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`
do
        result=`find dir2/ -samefile dir1/firstfile`
        if [ result  != "" ]
        then
                echo "Duplicate: " $i
        fi
done

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

share|improve this answer
#!/bin/sh
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
share|improve this answer

Your Answer

 
discard

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.