Menu
- App For Mac That Tell Size Of Folder And File Structure
- How To Tell Size Of Copper Pipe
- How To Tell Size Of Bike Frame
- App For Mac That Tell Size Of Folder And Files
Active5 months ago
Is there a simple command to display the total aggregate size (disk usage) of all files in a directory (folder)?
As a quick reminder, you can open Spotlight search by hitting the Command+Spacebar key combo from anywhere in Mac OS and Mac OS X, and you can open a new Finder search with Command+F from anywhere in the Mac file system, desktop, or Finder.
I have tried these, and they don't do what I want:
ls -l
, which only displays the size of the individual files in a directory, nordf -h
, which only displays the free and used space on my disks.
20.3k1414 gold badges6161 silver badges106106 bronze badges
David BarryDavid Barry3,96333 gold badges1212 silver badges88 bronze badges
12 Answers
The command
du
'summarizes disk usage of each FILE, recursively for directories,' e.g.,-h
is to get the numbers 'human readable', e.g. get140M
instead of143260
(size in KBytes)-s
is for summary (otherwise you'll get not only the size of the folder but also for everything in the folder separately)
As you're using
-h
you can sort the human readable values usingThe
-h
flag on sort
will consider 'Human Readable' size values.If want to avoid recursively listing all files and directories, you can supply the
Marcel StimbergMarcel Stimberg--max-depth
parameter to limit how many items are displayed. Most commonly, --max-depth=1
28k77 gold badges4141 silver badges4444 bronze badges
Recently I found a great, ncurses based interactive tool, that quickly gives you an overview about directory sizes. Searched for that kind of tool for years.
- quickly drilldown through file hierarchy
- you can delete e.g. huge temporary files from inside the tool
- extremely fast
Think of it as baobab for the command line:
geekQgeekQ
1,90511 gold badge1111 silver badges1313 bronze badges
This finds the size recursively and puts it next to each folder name, along with total size at the bottom, all in the human format
BradBrad
myusuf3myusuf314k3434 gold badges8181 silver badges9999 bronze badges
tree
is another useful command for this job:Just install it via
sudo apt-get install tree
and type the following:From man tree:
αғsнιηαғsнιη25.7k2323 gold badges105105 silver badges167167 bronze badges
Below is what I am using to print total, folder, and file size:
Details
Output
Peter Mortensen1,02722 gold badges1111 silver badges1717 bronze badges
vivekyad4vvivekyad4v32911 gold badge44 silver badges1111 bronze badges
The answers have made it obvious that
du
is the tool to find the total size of a directory. However, there are a couple of factors to consider:- Occasionally,
du
output can be misleading because it reports the space allocated by the filesystem, which may be different from the sum of the sizes of the individual files. Typically the filesystem will allocate 4096 bytes for a file even if you stored just one character in it! - Output differences due to power of 2 and power of 10 units. The
-h
switch todu
divides the number of bytes by 2^10 (1024), 2^20 (1048576) etc to give a human readable output. Many people might be more habituated to seeing powers of 10 (e.g. 1K = 1000, 1M = 1000000) and be surprised by the result.
To find the total sum of sizes of all files in a directory, in bytes, do:
Example:
pdppdp
For only the directory size in a readable format, use the below:
This probably isn't in the correct section, but from the command line, you could try:
The
-s
is size, and the -h
is human readable.Use
Peter Mortensen-l
to show on ls
list, like below:1,02722 gold badges1111 silver badges1717 bronze badges
Shiv SinghShiv Singh3,60222 gold badges99 silver badges1010 bronze badges
du /foldername
is the standard command to know the size of a folder. It is best practice to find the options by reading the man page:You should read the man page (available online) before you use the command.
Balaswamy vaddemanBalaswamy vaddeman
Here is a POSIX script that will work with:
- A file
- Files
- A directory
- Directories
Steven PennySteven Penny
If your desired directory has many sub-directories then, use the following:
-c, --total produce a grand total
-s, --summarize display only a total for each argument
-h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
-s, --summarize display only a total for each argument
-h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
which would then produce a overall total of the memory usage by all files/folders in the current directory.
kmario23kmario2344211 gold badge33 silver badges1717 bronze badges
The best one I think is the following:
This will show you only the size of the directory that you are interested in and will not print sizes of any directories and files inside that directory.
I should add that if the size of the folder is large then du takes longer time. You must be patient for this command to work. Just like any other unix command, you may find out the total time for this process by using
time
before this command:PeacefulPeaceful
protected by αғsнιηNov 19 '17 at 3:18
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?
Not the answer you're looking for? Browse other questions tagged filesystemcommand-line or ask your own question.
Question:
Mac Geek Gab listener Daryn writes, “I recently have been trying to figure out if there’s a way to see the size of a directory when using Terminal in Recovery Mode. I would like to know how much space I may need when trying to pull data from a volume on a Mac to an external device.
I occasionally have to backup data from Terminal in Recovery Mode due to filesystem damage or other issues. I’m wondering if you guys know of any way to see the size of a whole directory while in the Terminal?”
Answer:
Absolutely, Daryn!
The command you’ll want to use from the Terminal is ‘du‘ which is short for, “display disk usage statistics”. Just invoking ‘du‘ will give you too detailed of a list (and not the answer you want), but with a couple of switches and a filename target you’ll get what you’re looking for. From the Terminal, type: du -sh * and that will give you a listing of your files and folders with their sizes.
App For Mac That Tell Size Of Folder And File Structure
By issuing ‘du -sh *’ in the Terminal I can see the sizes of all my files and foldersSo you understand what you just typed (or are about to type):
du – that’s the command -s – this switch tells ‘du’ to show you one line per filename specified -h – this switch tells ‘du’ to output the sizes in ‘human-readable’ format. Because we’re using two switches, s and h, we can combine them together with ‘ -sh‘ * – this is the filename target, and the asterisk means “everything that doesn’t start with a period.” You could specify a single directory here or a list, or individual files. du will take them all.
How To Tell Size Of Copper Pipe
For anyone doing this from the Terminal of a normally-booted Mac, this will work exactly as you see above. Unfortunately Recover Mode is a little different because the ‘du’ command isn’t included in the skeleton system you’re running. You’ll have to point to a different volume that contains it. Thankfully, your Mac’s normal hard drive has this, and it will work even if it’s in read-only mode. You’d modify the above command and add “/Volumes/[Volume Name]/usr/bin/” to the beginning of the statement, where [Volume Name] is the name of your hard drive. If your hard drive name contains a space, it’s safer to wrap the whole thing in double quotes as I have just to make life easier.
My hard drive is named “Back Seat Betty” because I name all my drives after Miles Davis songs, so for me that command would be:
The Terminal can be both handy and efficient, not to mention fun. Tread thoughtfully and deliberately, and always remember to use the ‘man‘ command to get details if you’re unsure. For today’s lesson, typing ‘man du‘ will give you more information about the ‘du’ command than you ever wanted. Enjoy!
How To Tell Size Of Bike Frame
This question was originally answered on MGG 618: Quick Tips, iCloud Music and Resistant Clients