Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Linux/macOS - Shell...
 
Share:
Notifications
Clear all

[Solved] Linux/macOS - Shell - List directory sizes ...

1 Posts
1 Users
0 Likes
924 Views
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2703
Topic starter  

How does one list all directories, and see the space each directory takes up on your disk, in a given directory?

I rarely need this, but I do find myself having to Google it each time I do ... 
So for my own reference, and maybe for others as well:

(works in a Linux Shell or macOS Terminal)

du -sh /path/to/directory/*

This will list all directory in "/path/to/directory/", with it's size.

For example:

~ $ du -sh /Users/username/*                                                                                                              12:25
 30M	/Users/username/Applications
1.3M	/Users/username/Applications (Parallels)
 24M	/Users/username/Creative Cloud Files
1.1G	/Users/username/Desktop
235G	/Users/username/Documents
 18G	/Users/username/Downloads
 12K	/Users/username/Fusion 360
129G	/Users/username/Library
144K	/Users/username/Movies
 1M	/Users/username/Music
1.3M	/Users/username/untitled folder

Explanation

"du" (disk usage) command estimates the space usage. Note: only for directories you have access to!!!
The Linux Man page and Apple man page can give you more details.

The options we use here: -sh

-s, --summarize; display only a total for each argument

-h, --human-readable; print sizes in human readable format (e.g., 1K 234M 2G)

Optional:
-c, --total; produce a grand total


   
ReplyQuote
Share: