0

In a different question I discovered that "There are a few dirs which you should not run du against", and that "The output should tell you what has been completed and what the next is causing the hang". However, it's not possible to determine what "the next" would be unless you know the order in which du checks directories. What is that order? It doesn't appear to be based on name, last modification time, last access time, or creation time (confirmed by checking the output of du --max-depth=1 2>/dev/null against ls --time=[ctime/atime/birth]), and it's not describe in man du or here.

(I recognize that this information isn't necessary in order to resolve my initial problem - I can just try du against sets of directories until I find the problematic ones. But I'm curious!)

(Apologies for the overly-broad tag, but there is no specific du tag, and it's not possible to submit a question without a tag)

scubbo
  • 113
  • "The next" is determined by whatever order happens to come out of the filesystem when readdir() is called, it's an implementation detail. There's no real contract or well defined order there. If you require an order, you might consider feeding a list in whatever order you like to du instead of having it iterate files and directories itself. – Chris Down Jan 13 '23 at 05:43
  • Great, thanks! Would you like to submit that as an answer so I can accept it? – scubbo Jan 13 '23 at 05:56
  • 2
    FWIW, ls -f would likely also display the directory entries in this unsorted order. – Kusalananda Jan 13 '23 at 06:28

1 Answers1

0

There is no particular order. It lists objects in the order they appear in the directories, essentially random. (This is what makes the comment you are citing wrong — you can't know what will go next just by observing already completed entries.)

The only ordering you could have is that it respects the order of roots you've given it at the command line; so, say if you run it like du /home /var, it will run through all elements in /home in random order and then it will output whatever is in /var in random order.

Also, it should be not much of a problem running it through /proc.

However, if you want to exclude some directories, there are some switches:

       -X, --exclude-from=FILE
              exclude files that match any pattern in FILE
   --exclude=PATTERN
          exclude files that match PATTERN

   -x, --one-file-system
          skip directories on different file systems

For instance, du -x / will definitely skip /proc and /sys because those are mounted virtual file systems.

  • Thanks! I'd come across the exclusion flags, and also the ability to pass a pre-sorted list to du - I was just curious about the underlying mechanism. – scubbo Jan 13 '23 at 05:56