Linux: find the size of the folders and files in a directory

Linux: find the size of the folders and files in a directory

Using Linux and want to know the total size of a folder or file?

For this, we use the "du" command, which stands for "Disk Usage".

du -h

The "h" option stands for "human readable", which displays the result in KB, MB, GB...

Show the total size of a directory

du -sh /monrepertoire

The -s option shows only the total size of the directory

Then sort by size to spot the largest directories

du -sh /monrepertoire/* | sort -hr

Sort is used to sort the results:
- h means "human" output, in other words human-readable sizes
- r reverses the order so the largest directories are shown first.

Show the size of each directory, sorted by size

du -h --max-depth=1 | sort -hr

--max-depth=1 shows only first-level directories

Have a web project in mind?

Website design, e-commerce or SEO: our web agency in Paris, Besançon and Normandy can help.

Free quote

Related articles