Get the size of a directory/file on GNU/Linux

Desktops such as GNOME, KDE, LXDE, XFCE offer an easy way to determine the size of a file or directory, right-click on the file in question, select properties from the context menu, but for servers we don't get any desktop then we should use du command which calculates the space occupied by a file or directory

To get the size of a file / directory, type:
$ du -sh directorio

where:

  • -s: displays the total for each argument
  • -h: display the size of each file in a readable format (K, M, G)
In order to obtain the total size for each file that belongs to a directory, type:
$ du -csh directorio/*

-c: prints the total

Recommended reading

-man du

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.