I'm trying to move some data over and to start with I'd like to make sure that the size is ok. I run into a problem however, if I check the folder with

du -sh  myfolder/
780M    myfolder/


du -sh *
71M     myfolder

I thought it might be something to do with hidden files but this particular folder does not have any inside.

Am I missing something?

  • Do you have a ~709 MB file being added to / deleted from myfolder between operation? A file being written to? A file being linked to myfolder? If you don't then it looks like a bug in your du. – Satō Katsura Mar 29 '17 at 15:25
  • Do you have hidden files? ls -lhA myfolder – Giacomo Catenazzi Mar 29 '17 at 16:41

Chances are that myfolder contains 709 MB worth of files that have another hard link in a subdirectory that is sorted lexicographically before myfolder. The du command reports each distinct file only the first time it sees it, so if a file has multiple links inside the tree(s) covered by a run of du, it's reported only once, under whichever directory was traversed first.

Here are a few ways you can look for hard links:

  • find myfolder -links +1 -type f lists all the files that have at least a second hard link under myfolder (+1 means “more than one”), regardless of where that link is.
  • find . -samefile myfolder/foo (with GNU find) lists all the hard links to myfolder/foo under the current directory. Since myfolder is under the current directory, this includes myfolder/foo itself.
  • find -type f -links +1 -printf '%i %p\n' | sort -k1n (with GNU find) produces a list of hard-linked files under the current directory, grouped by inode number. Two files are the same if they are located on the same filesystem and they have the same inode number.
  • This might be the case, I'll check this out. Thanks @Gillles – Bart C Mar 30 '17 at 11:22
  • Yes, with find . -samefile ... I found multiple hard links all over the place, thanks again. – Bart C Mar 30 '17 at 11:38
  • Following on the subject, ls -l displays a number next to the permissions which indicates a count of hard links on the file – Bart C Apr 3 '17 at 9:50

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.