Command for folder size?
Thu, 2006-03-02 17:52
What's the Linux command for determining folder size? I've never had to do that before. Note I don't mean "df -h" and "ls -al" only tells me the size of the folder's entry on the disk, not the contents as well.










My buddy (swell coworker from Brazil) wrote back:
You can use du to check size on folder and subfolders.
There are some options as -h and -k for size format and -s to summarize.
Please, be careful with folders where you have a large number of files. You may want to do CTRL+C if it takes too long on a production server.
I didn't know about the du command. Awesome, thanks for posting!
If you're looking for things to delete / move to an archive to make some space quickly (that is, not systematically, because you're in a hurry), try this:
du -a | sort -rn | less
Don't try it in / , but your home directory should be fine. It has saved me a few times when I was running out of quota.
If you're looking for things to delete / move to an archive to make some space quickly (that is, not systematically, because you're in a hurry), try this:
du -a | sort -rn | less
Don't try it in / , but your home directory should be fine. It has saved me a few times when I was running out of quota.
That is a righteous tip. Thanks! I used it just now on my home dir to check some things.
Or you could do this for an awesome output
which gives output like:
104.0000 kb rexima-1.4 101.3994 mb tremulous-1.1.0-installer.x86.run 1.1494 mb wrar37b3.exe 1.1041 gb archthe sizes perl script is:
#!/usr/bin/env perl # Formats output of du. # # example: $ du -sc * | sort -n | perl -e sizes # # output: # # 104.0000 kb rexima-1.4 # 101.3994 mb tremulous-1.1.0-installer.x86.run # 1.1494 mb wrar37b3.exe # 1.1041 gb arch # # written by spyro_boy / use warnings; use strict; while(my $num=) { my $i=0; # add more, I'm too lazy to search up all the acronyms my @units = ("b","kb","mb","gb","tb"); if(my @m=($num =~ m/^([0-9]+)\s+(.+)/)) { my $size=$m[0]; do { $size = $size/1024; $i++; } while($size>1); $size = $size*1024; printf "%10.4f %s %s\n",$size,$units[$i],$m[1]; } }I wrote it myself. Enjoy!
I wrote a Bash script to do this. You need this in your $PATH for it to work. It gives file sizes, not disk usage like du does.
I wrote a Bash script to do this. You need this in your $PATH for it to work. It gives file sizes, not disk usage like du does.
link fails. is there a mirror?