View Full Version : How to du -sm all?
huangyingw
August 20th, 2011, 10:43 AM
Hello,
I have run such command, with intention to calculate the size of all sub folders under /home/huangyingw
root@desktop:/home/huangyingw# du -sm /home/huangyingw/*|sort -n
But in fact, I found that, the hidden folder like /home/huangw/.android, /home/huangyingw/.mozilla, could not be listed.
How could I list all sub directories , including those .* directories, in one command?
The Cog
August 20th, 2011, 11:54 AM
I can think if a couple of ways, but they're not very nice.
This first one launches du many times:
find . -maxdepth 1 -type d -exec du -sh '{}' \;
This one needs to set IFS to be able to handle filenames with spaces:
IFS=$'\n'
du -sh $(find . -maxdepth 1 -type d)
sisco311
August 20th, 2011, 12:12 PM
In bash you can enable the dotglob option:
shopt -s dotglob
du -sh *
shopt -u dotglob
ofnuts
August 20th, 2011, 02:09 PM
I can think if a couple of ways, but they're not very nice.
This first one launches du many times:
find . -maxdepth 1 -type d -exec du -sh '{}' \;
If you terminate your grep -exec command with '+' instead of ';' the command is called only once on all the files together.
SeijiSensei
August 20th, 2011, 02:38 PM
du -s \.?*
will display the hidden directories.
sisco311
August 20th, 2011, 02:55 PM
du -s \.?*
will display the hidden directories.
That will also match .. (the hardlink to the parent directory).
. is no a special character, so you don't have to quote it.
You can match all the dot files, but not . or .. with two globs:
echo .[^.]* ..?*
Or you could use the GLOBIGNORE variable:
GLOBIGNORE=.:..
echo .*
huangyingw
August 20th, 2011, 04:17 PM
I can think if a couple of ways, but they're not very nice.
This first one launches du many times:
find . -maxdepth 1 -type d -exec du -sh '{}' \;
This one needs to set IFS to be able to handle filenames with spaces:
IFS=$'\n'
du -sh $(find . -maxdepth 1 -type d)
Really, your solution is too complicated.
huangyingw
August 20th, 2011, 04:19 PM
In bash you can enable the dotglob option:
shopt -s dotglob
du -sh *
shopt -u dotglob
I appreciate this solution.:popcorn:
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.