I am working on a Debian server where I have only console access without sudo. The main folder called applications includes subfolders with all the projects I have.

However, when I create a new project through my admin panel, the folder name is a nonsense string and you can rename it by creating a symlink to a new folder.

So, of example, the applications folder is like that:


I want to check how much space each of the applications use. Since I don't have a lot of experience in Unix, I googled and I found that I can do it with du -sh *.

However, the output is like that:

91M     abuwryjbrb                                                                                                                                                 
201M    evharjqgxj                                                                                                                                                
0       MyCustomProjectName1                                                                                                                                          
0       MyCustomProjectName2

As a result, it is too time consuming for me to check one by one the names and see which folder is which.

Is there any way to get an output with the disk usage for the symlinks instead?


Using du -sh -L * instead, I don't get duplicated folders for both original and symlinked, but I get a mixed output like this:

91M     abuwryjbrb                                                                                                                                                 
201M    MyCustomProjectName1  

Where some of the folders have the original name and some the symlink name


You can get usage of symlinks using -L flag along with du command. du -sh -L * should help you.

  • I get a list of all folders without duplicates, but some are with the symlinks name and others with the original name. – Tasos Jun 25 '17 at 9:00
  • @Tasos I didn't get you, you cannot create duplicates? so du will list all the directories inside applications directory. When you use -L flag it should show size of original directory as well as size of symlink . But for directories which are not linked, it should show only original name and size. If you have hard links too, then using -l flag will help, so try du -sh -l -L * . – Chetna C Jun 25 '17 at 9:04
  • 1
    That's did the work. As I said, the symlink is created automatically from my admin dashboard, so I didn't know the difference on the links. Thank you a lot – Tasos Jun 25 '17 at 9:12
du -sh */

The trailing slash causes the wildcard to match directories and symbolic links to directories. For symbolic links to directories, the command acts on the target.

Your projects will be listed twice, once for each directory and once for its symbolic link. You can avoid that if there's an easy way to make a wildcard pattern that only matches your own names. For example, if you always capitalize your own names and the automatic ones are always lowercase, you can use

du -sh [A-Z]*/

Alternatively, you can use

du -shD *

This lists regular files as well. The option -D tells du to dereference symbolic links passed on the command line. Symbolic links inside each directory tree are not traversed (unlike -L, which is not a good idea here).

In zsh, you can use

du -sc *(@-/)

to act only on symbolic links to directories, or du -sc *(@) to act only on symbolic links whatever their target.

In any shell, you can use

find . -maxdepth 1 -type l -xtype d -exec du -sh {} +

to act only on symbolic links to directories.

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.