Tips Tricks Tutorials

WEB-NES-BAY

Learn Tips and tricks on Linux, Hacking, linux, PHP, Perl, Web, Hardware

bookmark bookmark
WEBNESBAY On June - 27 - 2009

Have you ever wondered which directories and trees take up all the diskspace? Questions like this come during pruning/archiving, backup, and numerous other activities. Make the following oneliner script (I call it dirsizes) to find out:

du -sm $(find $1 -type d -maxdepth 1 -xdev) | sort -g

The preceding shellscript prints every directory below the one called as an argument, together with its size, sorted with the largest at the bottom. We sort largest at bottom so there’s no necessity to pipe it toless. Instead, you can see the largest 24 on the screen after the command.

If you find a large tree, but can’t delete the whole thing, you can explore just that tree by using its directory as the argument, and you’ll see all its subtrees and how much space they take.

But let’s say you want to see ALL directories in the tree, instantly zeroing in on big diskspace directories. Make the following shellscript, which I call alldirsizes:

find $1 -type d  | xargs du -sm | sort -g

Both these scripts do more than just add filesizes. They take into account inodes, so they reveal the space that would be recovered if the directories were deleted.

Both of these scripts are most accurate when run as root, but they’re pretty informative run as just a normal user.

Related posts:

  1. How to make reverse sort in perl array
  2. RSS Clients for Linux
  3. Download youtube videos in ubuntu linux
  4. Compiling mplayer with multi-core decoding support in ubuntu linux
  5. How to use crontab in Ubuntu/Linux
  6. Differences between df and du command in linux
  7. Linux Keylogger in Ubuntu
Categories: Linux

Leave a Reply