I have a directory structure where there are multiple symlinks at random depths.

For illustration purpose:

/fs/blink -> /usr/local/lib
/fs/cdir/cdir/cdir/clink -> /var/log
/fs/edir/elink -> /usr/local/bin

I want to find which file or folder utilizes the most space to do some cleanup. I am hoping an output similar to:

3.0G     /fs
4.0G     /fs/afile
3.3G     /fs/cdir
15.0G    /fs/edir

I tried running cd /fs && find -maxdepth 1 -type d | sudo xargs du -hs but this expands the symlinks underneath, which means the size of /fs/edir would include the content and size of /usr/local/bin in this case.

TLDR: For a given path, how do I find the size of all files or directories at depth=1, without expanding any underneath symlinks?

Note: I read du skip symbolic links but this case is different as the symlink in this case could be of any depth.

  • 1
    Is your du an alias? The standard mandates du not to follow symlinks by default, anywhere in the file hierarchy. And neither does the GNU du I'm testing with. – fra-san Mar 22 '19 at 8:57
  • Interesting, I thought symlinks were expanded because the size I get from du is larger than the df total disk space. Maybe I am missing something else here... – Victor Wong Mar 22 '19 at 9:56
  • 1
    Then you should look for mount points. If some other device is mounted under /fs, then du will include it in its results unless you use its -x (skip directories on different file systems) option. – fra-san Mar 22 '19 at 10:46

Your Answer

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

Browse other questions tagged or ask your own question.