Is there any du (disk usage) command flag that summarizes the size for each sub-directory

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
4
down vote

favorite












I have the following directory structure (example) -



main
|--src
|--com
|- company
|--org
|- apache
|--resources
|--abc
|--etc


I need the disk space used by each sub-directory under the main directory. So, the output would be something like -



user@main> du -command_switches
1M src
20M resources
3M etc


I have tried several switches available - sh, Sh, ash, aSH - but I could not get the required result.



Any suggestions in this direction would really help.







share|improve this question

















  • 2




    If you don't need that information put it a file or something like that, you could try ncdu which shows what you need in an interactive TUI environment.
    – Mioriin
    Apr 27 at 13:26














up vote
4
down vote

favorite












I have the following directory structure (example) -



main
|--src
|--com
|- company
|--org
|- apache
|--resources
|--abc
|--etc


I need the disk space used by each sub-directory under the main directory. So, the output would be something like -



user@main> du -command_switches
1M src
20M resources
3M etc


I have tried several switches available - sh, Sh, ash, aSH - but I could not get the required result.



Any suggestions in this direction would really help.







share|improve this question

















  • 2




    If you don't need that information put it a file or something like that, you could try ncdu which shows what you need in an interactive TUI environment.
    – Mioriin
    Apr 27 at 13:26












up vote
4
down vote

favorite









up vote
4
down vote

favorite











I have the following directory structure (example) -



main
|--src
|--com
|- company
|--org
|- apache
|--resources
|--abc
|--etc


I need the disk space used by each sub-directory under the main directory. So, the output would be something like -



user@main> du -command_switches
1M src
20M resources
3M etc


I have tried several switches available - sh, Sh, ash, aSH - but I could not get the required result.



Any suggestions in this direction would really help.







share|improve this question













I have the following directory structure (example) -



main
|--src
|--com
|- company
|--org
|- apache
|--resources
|--abc
|--etc


I need the disk space used by each sub-directory under the main directory. So, the output would be something like -



user@main> du -command_switches
1M src
20M resources
3M etc


I have tried several switches available - sh, Sh, ash, aSH - but I could not get the required result.



Any suggestions in this direction would really help.









share|improve this question












share|improve this question




share|improve this question








edited Apr 27 at 9:23









muru

33.2k576140




33.2k576140









asked Apr 27 at 9:19









Rakesh N

1235




1235







  • 2




    If you don't need that information put it a file or something like that, you could try ncdu which shows what you need in an interactive TUI environment.
    – Mioriin
    Apr 27 at 13:26












  • 2




    If you don't need that information put it a file or something like that, you could try ncdu which shows what you need in an interactive TUI environment.
    – Mioriin
    Apr 27 at 13:26







2




2




If you don't need that information put it a file or something like that, you could try ncdu which shows what you need in an interactive TUI environment.
– Mioriin
Apr 27 at 13:26




If you don't need that information put it a file or something like that, you could try ncdu which shows what you need in an interactive TUI environment.
– Mioriin
Apr 27 at 13:26










3 Answers
3






active

oldest

votes

















up vote
10
down vote



accepted










Some du implementations support -d¹ to limit the depth at which disk usage is displayed (not at which disk usage is accounted), so du -hd 1 . should work for the current directory.



Portably, you can always do:



find . ! -name . -prune -type d -exec du -s +


(add -h if your du implementation supports it)



Though note that if there are a lot of directories in the current directory, find may end up running several invocations of du which could mean that some hard links are counted several times. Some du implementations also don't prevent hard links from being counted several times if they're encountered through the traversal of different arguments.




¹, with older versions of GNU du, you may need --max-depth instead. The -d short option equivalent was only added in coreutils 8.8 for compatibility with FreeBSD






share|improve this answer



















  • 2




    Also du -sh main/*.
    – Michael Homer
    Apr 27 at 9:28










  • @MichaelHomer, that would also report the disk usage of non-directory files and exclude hidden directory files. With zsh, you could do du -sh main/*(D/)
    – Stéphane Chazelas
    Apr 27 at 9:46


















up vote
2
down vote













You may want to look into




$ du --max-depth=1 -h




I know this thread is about du but you might also want to have a look at graphical applications, which can be more efficient at showing information like this, such as baobab or k4dirstat.






share|improve this answer























  • du -d (aka --max-depth in GNU du) is already mentioned in the accepted answer.
    – Stéphane Chazelas
    Apr 27 at 13:32











  • @Francisco, the graphical tools sound interesting. I will give them a shot. Thanks.
    – Rakesh N
    Apr 27 at 14:17

















up vote
0
down vote













Maybe I'm missing what you're asking for, but I think



du -sh *


does exactly what you want. The * is important here. With -s, you get a summary for each directory on the command line, so with no explicit dir (implicit .) you would just get a summary for everything, not the for each of the dirs under the top-level individually.






share|improve this answer





















  • I tried this command. It does not include directories start with .
    – Rakesh N
    Apr 30 at 12:09










  • @RakeshN: If you want to include them you need either add extra patterns for them (.[!.]* ..?*) or use the bash-specific shopt -s dotglob to make * match dotfiles.
    – R..
    Apr 30 at 16:11










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f440369%2fis-there-any-du-disk-usage-command-flag-that-summarizes-the-size-for-each-sub%23new-answer', 'question_page');

);

Post as a guest






























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
10
down vote



accepted










Some du implementations support -d¹ to limit the depth at which disk usage is displayed (not at which disk usage is accounted), so du -hd 1 . should work for the current directory.



Portably, you can always do:



find . ! -name . -prune -type d -exec du -s +


(add -h if your du implementation supports it)



Though note that if there are a lot of directories in the current directory, find may end up running several invocations of du which could mean that some hard links are counted several times. Some du implementations also don't prevent hard links from being counted several times if they're encountered through the traversal of different arguments.




¹, with older versions of GNU du, you may need --max-depth instead. The -d short option equivalent was only added in coreutils 8.8 for compatibility with FreeBSD






share|improve this answer



















  • 2




    Also du -sh main/*.
    – Michael Homer
    Apr 27 at 9:28










  • @MichaelHomer, that would also report the disk usage of non-directory files and exclude hidden directory files. With zsh, you could do du -sh main/*(D/)
    – Stéphane Chazelas
    Apr 27 at 9:46















up vote
10
down vote



accepted










Some du implementations support -d¹ to limit the depth at which disk usage is displayed (not at which disk usage is accounted), so du -hd 1 . should work for the current directory.



Portably, you can always do:



find . ! -name . -prune -type d -exec du -s +


(add -h if your du implementation supports it)



Though note that if there are a lot of directories in the current directory, find may end up running several invocations of du which could mean that some hard links are counted several times. Some du implementations also don't prevent hard links from being counted several times if they're encountered through the traversal of different arguments.




¹, with older versions of GNU du, you may need --max-depth instead. The -d short option equivalent was only added in coreutils 8.8 for compatibility with FreeBSD






share|improve this answer



















  • 2




    Also du -sh main/*.
    – Michael Homer
    Apr 27 at 9:28










  • @MichaelHomer, that would also report the disk usage of non-directory files and exclude hidden directory files. With zsh, you could do du -sh main/*(D/)
    – Stéphane Chazelas
    Apr 27 at 9:46













up vote
10
down vote



accepted







up vote
10
down vote



accepted






Some du implementations support -d¹ to limit the depth at which disk usage is displayed (not at which disk usage is accounted), so du -hd 1 . should work for the current directory.



Portably, you can always do:



find . ! -name . -prune -type d -exec du -s +


(add -h if your du implementation supports it)



Though note that if there are a lot of directories in the current directory, find may end up running several invocations of du which could mean that some hard links are counted several times. Some du implementations also don't prevent hard links from being counted several times if they're encountered through the traversal of different arguments.




¹, with older versions of GNU du, you may need --max-depth instead. The -d short option equivalent was only added in coreutils 8.8 for compatibility with FreeBSD






share|improve this answer















Some du implementations support -d¹ to limit the depth at which disk usage is displayed (not at which disk usage is accounted), so du -hd 1 . should work for the current directory.



Portably, you can always do:



find . ! -name . -prune -type d -exec du -s +


(add -h if your du implementation supports it)



Though note that if there are a lot of directories in the current directory, find may end up running several invocations of du which could mean that some hard links are counted several times. Some du implementations also don't prevent hard links from being counted several times if they're encountered through the traversal of different arguments.




¹, with older versions of GNU du, you may need --max-depth instead. The -d short option equivalent was only added in coreutils 8.8 for compatibility with FreeBSD







share|improve this answer















share|improve this answer



share|improve this answer








edited Apr 29 at 22:27









Jeff Schaller

31.1k846105




31.1k846105











answered Apr 27 at 9:22









emmrk

17913




17913







  • 2




    Also du -sh main/*.
    – Michael Homer
    Apr 27 at 9:28










  • @MichaelHomer, that would also report the disk usage of non-directory files and exclude hidden directory files. With zsh, you could do du -sh main/*(D/)
    – Stéphane Chazelas
    Apr 27 at 9:46













  • 2




    Also du -sh main/*.
    – Michael Homer
    Apr 27 at 9:28










  • @MichaelHomer, that would also report the disk usage of non-directory files and exclude hidden directory files. With zsh, you could do du -sh main/*(D/)
    – Stéphane Chazelas
    Apr 27 at 9:46








2




2




Also du -sh main/*.
– Michael Homer
Apr 27 at 9:28




Also du -sh main/*.
– Michael Homer
Apr 27 at 9:28












@MichaelHomer, that would also report the disk usage of non-directory files and exclude hidden directory files. With zsh, you could do du -sh main/*(D/)
– Stéphane Chazelas
Apr 27 at 9:46





@MichaelHomer, that would also report the disk usage of non-directory files and exclude hidden directory files. With zsh, you could do du -sh main/*(D/)
– Stéphane Chazelas
Apr 27 at 9:46













up vote
2
down vote













You may want to look into




$ du --max-depth=1 -h




I know this thread is about du but you might also want to have a look at graphical applications, which can be more efficient at showing information like this, such as baobab or k4dirstat.






share|improve this answer























  • du -d (aka --max-depth in GNU du) is already mentioned in the accepted answer.
    – Stéphane Chazelas
    Apr 27 at 13:32











  • @Francisco, the graphical tools sound interesting. I will give them a shot. Thanks.
    – Rakesh N
    Apr 27 at 14:17














up vote
2
down vote













You may want to look into




$ du --max-depth=1 -h




I know this thread is about du but you might also want to have a look at graphical applications, which can be more efficient at showing information like this, such as baobab or k4dirstat.






share|improve this answer























  • du -d (aka --max-depth in GNU du) is already mentioned in the accepted answer.
    – Stéphane Chazelas
    Apr 27 at 13:32











  • @Francisco, the graphical tools sound interesting. I will give them a shot. Thanks.
    – Rakesh N
    Apr 27 at 14:17












up vote
2
down vote










up vote
2
down vote









You may want to look into




$ du --max-depth=1 -h




I know this thread is about du but you might also want to have a look at graphical applications, which can be more efficient at showing information like this, such as baobab or k4dirstat.






share|improve this answer















You may want to look into




$ du --max-depth=1 -h




I know this thread is about du but you might also want to have a look at graphical applications, which can be more efficient at showing information like this, such as baobab or k4dirstat.







share|improve this answer















share|improve this answer



share|improve this answer








edited Apr 27 at 13:22


























answered Apr 27 at 13:14









Francisco

1607




1607











  • du -d (aka --max-depth in GNU du) is already mentioned in the accepted answer.
    – Stéphane Chazelas
    Apr 27 at 13:32











  • @Francisco, the graphical tools sound interesting. I will give them a shot. Thanks.
    – Rakesh N
    Apr 27 at 14:17
















  • du -d (aka --max-depth in GNU du) is already mentioned in the accepted answer.
    – Stéphane Chazelas
    Apr 27 at 13:32











  • @Francisco, the graphical tools sound interesting. I will give them a shot. Thanks.
    – Rakesh N
    Apr 27 at 14:17















du -d (aka --max-depth in GNU du) is already mentioned in the accepted answer.
– Stéphane Chazelas
Apr 27 at 13:32





du -d (aka --max-depth in GNU du) is already mentioned in the accepted answer.
– Stéphane Chazelas
Apr 27 at 13:32













@Francisco, the graphical tools sound interesting. I will give them a shot. Thanks.
– Rakesh N
Apr 27 at 14:17




@Francisco, the graphical tools sound interesting. I will give them a shot. Thanks.
– Rakesh N
Apr 27 at 14:17










up vote
0
down vote













Maybe I'm missing what you're asking for, but I think



du -sh *


does exactly what you want. The * is important here. With -s, you get a summary for each directory on the command line, so with no explicit dir (implicit .) you would just get a summary for everything, not the for each of the dirs under the top-level individually.






share|improve this answer





















  • I tried this command. It does not include directories start with .
    – Rakesh N
    Apr 30 at 12:09










  • @RakeshN: If you want to include them you need either add extra patterns for them (.[!.]* ..?*) or use the bash-specific shopt -s dotglob to make * match dotfiles.
    – R..
    Apr 30 at 16:11














up vote
0
down vote













Maybe I'm missing what you're asking for, but I think



du -sh *


does exactly what you want. The * is important here. With -s, you get a summary for each directory on the command line, so with no explicit dir (implicit .) you would just get a summary for everything, not the for each of the dirs under the top-level individually.






share|improve this answer





















  • I tried this command. It does not include directories start with .
    – Rakesh N
    Apr 30 at 12:09










  • @RakeshN: If you want to include them you need either add extra patterns for them (.[!.]* ..?*) or use the bash-specific shopt -s dotglob to make * match dotfiles.
    – R..
    Apr 30 at 16:11












up vote
0
down vote










up vote
0
down vote









Maybe I'm missing what you're asking for, but I think



du -sh *


does exactly what you want. The * is important here. With -s, you get a summary for each directory on the command line, so with no explicit dir (implicit .) you would just get a summary for everything, not the for each of the dirs under the top-level individually.






share|improve this answer













Maybe I'm missing what you're asking for, but I think



du -sh *


does exactly what you want. The * is important here. With -s, you get a summary for each directory on the command line, so with no explicit dir (implicit .) you would just get a summary for everything, not the for each of the dirs under the top-level individually.







share|improve this answer













share|improve this answer



share|improve this answer











answered Apr 27 at 17:36









R..

1,473913




1,473913











  • I tried this command. It does not include directories start with .
    – Rakesh N
    Apr 30 at 12:09










  • @RakeshN: If you want to include them you need either add extra patterns for them (.[!.]* ..?*) or use the bash-specific shopt -s dotglob to make * match dotfiles.
    – R..
    Apr 30 at 16:11
















  • I tried this command. It does not include directories start with .
    – Rakesh N
    Apr 30 at 12:09










  • @RakeshN: If you want to include them you need either add extra patterns for them (.[!.]* ..?*) or use the bash-specific shopt -s dotglob to make * match dotfiles.
    – R..
    Apr 30 at 16:11















I tried this command. It does not include directories start with .
– Rakesh N
Apr 30 at 12:09




I tried this command. It does not include directories start with .
– Rakesh N
Apr 30 at 12:09












@RakeshN: If you want to include them you need either add extra patterns for them (.[!.]* ..?*) or use the bash-specific shopt -s dotglob to make * match dotfiles.
– R..
Apr 30 at 16:11




@RakeshN: If you want to include them you need either add extra patterns for them (.[!.]* ..?*) or use the bash-specific shopt -s dotglob to make * match dotfiles.
– R..
Apr 30 at 16:11












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f440369%2fis-there-any-du-disk-usage-command-flag-that-summarizes-the-size-for-each-sub%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay