Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Time Machine-style backup system set up on my NAS (running BusyBox v1.16.1), using rsync --link-dest as described here:

Is there an easy way to find out which files will be deleted if I delete an old backup directory, and which will just be unlinked? I assume one way would be to find which inodes in the old directory have only one link to them, but I don't know a way to do that. rm --dry-run anyone?

Bonus Points: Find a way to do the above, and also calculate the total disk space freed if the old backup is deleted.

share|improve this question
up vote 2 down vote accepted

A simple way would be to just use find with the -links option.

Specifically you would want to do something like find path -type f -links 1.

I haven't tested, but I believe a command like this would delete all the multi-linked files.

# you might not need to escape the !, depends on your shell
# should find all the files that do NOT have a link count of 1 and delete them
find path -type f \! links 1 -print -delete 
share|improve this answer
Thanks! This is perfect. I don't need the second part; since the backup images are full of hard links, I just need to delete the oldest backup directory. find oldest/ -type f -links 1 >> files-lost-forever.txt; find oldest/ -type f -links 1 -print0 | xargs -0 du | awk '{total = total + $1}END{print total " bytes freed"}'; rm -rf oldest; – JDS Jun 26 '12 at 5:15
er... s/du/du -k/ and s/bytes/Kb/ – JDS Jun 26 '12 at 6:44

Your Answer


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.