Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux get the size of a folder and its subfolders to a certain depth

In Linux, I have the following folder structure, I want to get the size of the folder and its subfolders to a certain depth.

I have this structure:

/AAAA/BBBB/1111
/AAAA/BBBB/2222
/AAAA/BBBB
/AAAA/CCCC
/AAAA/DDDD/3333
/AAAA/DDDD
/AAAA

du -m, shows me the entire tree, not just 2 levels as I need. What is the proper command?

like image 409
user1984646 Avatar asked Feb 06 '13 01:02

user1984646


People also ask

How do I find the size of a directory and subfolders in Linux?

To get the total size of a directory in Linux, you can use the du (disk-usage) command.

How do I find the size of a subfolder in Unix?

Display the size of one or more directories, subdirectories, and files by using the du command. Sizes are displayed in 512-byte blocks. Displays the size of each directory that you specify, including each subdirectory beneath it.

How do you check the size of a specific folder in Linux?

How to view the file size of a directory. To view the file size of a directory pass the -s option to the du command followed by the folder. This will print a grand total size for the folder to standard output. Along with the -h option a human readable format is possible.

How do I find the size of a specific folder?

You can display the size of directories by using the du command and its options. Additionally, you can find the amount of disk space taken up by user accounts on local UFS file systems by using the quot command. For more information about these commands, see du(1M)and quot(1M).


2 Answers

You want the -d or --max-depth option.

du -d 2
like image 118
Xymostech Avatar answered Oct 19 '22 16:10

Xymostech


Limit the depth of search --max-depth=N.

like image 29
X Tian Avatar answered Oct 19 '22 17:10

X Tian