How to list recursive file sizes of files and directories in a directory?
Solution 1
I guess the easiest way is by typing ls -l
, or ls -lh
which will provide the file size in human-readable format (KB, MB, etc).
If 'recursively' means listing all the subsequent folders, e.g.:
/foo/
/foo/bar/
....
Then you should also add parameter R
, like ls -lR
or ls -lhR
More information for ls
can be found by typing man ls
Update:
The following command as Lekensteyn proposed will probably do the job:
du -h --max-depth=1 <folder>
-h
is for human-readable
--apparent-size
is another way to display sizes as already stated
--max-depth
is the level of subfolders you want to go down to.
Solution 2
apt-get install ncdu
It is interactive too so if you want to check on a sub folder just UP, DOWN, and Enter to it.
Solution 3
To get the total size of a directory and all children
du -hs directory/*
Solution 4
Also check out tree
. It is not installed by default but is the repositories.
Example:
richard@legend:~$ tree Applications/ -s
Applications/
├── [ 4096] AlexFTPS-1.0.2
│ ├── [ 31232] AlexPilotti.FTPS.Client.dll
│ ├── [ 274432] C5.dll
│ ├── [ 1457] C5-License
│ ├── [ 35147] COPYING
│ ├── [ 7639] COPYING.LESSER
│ ├── [ 70] ftps
│ ├── [ 28672] ftps.exe
│ ├── [ 98304] Plossum CommandLine.dll
│ ├── [ 1557] Plossum-License
│ └── [ 2560] README
└── [ 4096] src
└── [ 180849] AlexFTPS_bin_1.0.2.zip
More options can be found in the man page.
Solution 5
Since you don't specifically mention you need a terminal-based solution, I think baobab a.k.a. Disk Usage Analyzer is missing from the list.
It is installed in Ubuntu by default and does exactly what you want in a nice graphical UI with the ability to drill down the directory hierarchy.
Apart from displaying a list of directories with their sizes, it is also showing a rings or treemap chart of filesystem usage, which is extremely useful for visualising the directories which take up the most space.
Related videos on Youtube
ndg
Updated on September 18, 2022Comments
-
ndg almost 2 years
How do I list all the files in a directory and their recursive file sizes?
---edit
I want to see the sizes 'rolled up' to the parent directories in the directory listed. I don't want to see the child directories or their contents or sizes.
-
Pavlos G. almost 13 yearsYou mean that you want to see the total size (sum) of all the files in a folder, like right-clicking on a folder on your desktop and selecting 'properties' ?
-
Lekensteyn almost 13 yearsAre you looking for software which helps you to find big files, or something to get a (collapsable) file tree?
-
ndg almost 13 yearsHi @Pavlos G - I mean the sum for each of the directories in the directory I'm currently in - not the sum for the overall directory.
-
Pavlos G. almost 13 years@J G - Check my update ;-)
-
-
ndg almost 13 yearsShould sizes be shown?
-
Richard Holloway almost 13 yearsJ G: The -s shows the sizes.
-
ndg almost 13 yearsI'd like the next level down from that - the recursive sizes of all the first level children.
-
Richard Holloway almost 13 yearsI'll edit my answer. You need to use du -h directory/*
-
Steven Lu almost 11 yearsShows the size of the directory record rather than full directory size.
-
nikoskip over 9 years@hawkeye for 1st level you can use
--max-depth=1
-
Lekensteyn over 9 years@nikoskip nice tip! Also nice to know is the shorthand,
--max-depth=1
can be shortened to-d1
. -
muru almost 9 yearsThis doesn't show the size of the directory.
-
Whimsical about 8 yearsgiven answer didnt give me details for simlinks(ls -lhR), the numbers listed next to it didnt correspond to the right size of each of the values either. My answer gave me a hierarchy with a defined tree structure and the correct answer....OR are you referring to some other upvoted answer?
-
Fabby about 8 yearsDown-vote retracted, upvoted. Please edit and put the comment in the answer... Thanks for the explanation. ;-)
-
SomethingSomething almost 7 yearsMaybe the most amazing software recommendation I have ever got
-
kRazzy R over 6 yearshow to get all of these in a decending order of size..
-
kRazzy R over 6 yearshow do I view the contents and empty : /dev/sda5 ext4 430G 381G 27G 94% / my laptop is less than 1 month old and it is so full which it makes no sense
-
dylanh724 over 6 yearsWhat to use for max depth? -1?
-
dvdmn about 5 yearsthis should be the approved answer
-
Eric almost 5 years
-h
show size in human readable way, e.gtree -s
-
qwr over 4 years4K is not the sizes of the directories
-
Jacquot over 4 years
ncdu
is really so underrated