Skip to main content
Welcome guest. | Register | Login | Post

Command for folder size?

7 replies [Last post]
supermike's picture
Offline
Joined: 2006-02-17

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.

supermike's picture
Offline
Joined: 2006-02-17

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.

libervisco's picture
Offline
Joined: 2006-05-04

I didn't know about the du command. Awesome, thanks for posting! Laughing out loud

tbuitenh's picture
Offline
Joined: 2005-12-21

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.

supermike's picture
Offline
Joined: 2006-02-17
"tbuitenh" wrote:

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.

Offline
Joined: 2006-01-02
Or you could do this for an

Or you could do this for an awesome output Sticking out tongue

du -s directory/or/files | sort -rn | perl -e sizes | less

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 arch

the 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!

a thing's picture
Offline
Joined: 2005-12-20
fsize

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.

Offline
Joined: 2006-01-02
fail
a thing wrote:

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?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.