DEV Community

Nic
Nic

Posted on • Originally published at coderscat.com on

2 1

Command Line to List Size of Directory (MacOS/Linux)

2020_03_31_command-to-list-size-of-directory.org_20200331_194953.png

I found the command du is different on Mac compared with Linux. A little bit of confusion.

Here is a note how to use du on different OS.

du on Mac

List the size of current directory, the option -h is displaying in human friendly format, the option -s is not recursive to display all sub-directories:

du -hs .
Enter fullscreen mode Exit fullscreen mode

List all the size of sub-directories in current directory:

find . -maxdepth 1 -mindepth 1 -type d -exec du -hs {} \;
Enter fullscreen mode Exit fullscreen mode

If you want to sort according to the size, use pipeline and sort:

find . -maxdepth 1 -mindepth 1 -type d | xargs du -hs | sort -hr
Enter fullscreen mode Exit fullscreen mode

If you want to know which directory cost most disk space, another handy util command line is ncdu. You could install it via homebrew:

brew install ncdu

# Run in the specific directory
ncdu
Enter fullscreen mode Exit fullscreen mode

The result is like this:

2020_03_31_command-to-list-size-of-directory.org_20200331_194324.png

du on Linux

Linux du have the option –max-depth to limit the depth:

du -h --max-depth=1 | sort -hr
Enter fullscreen mode Exit fullscreen mode

The post Command Line to List Size of Directory (MacOS/Linux) appeared first on Coder's Cat.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay