Skip to main content

Displaying sorted list(size wise) of Files/Folder on Linux

Even though i have a 120 GB HDD on my laptop and have dedicated a significant portion of hard disk space to Ubuntu still somehow every three or four months i run out of disk space . Also i am particularly bad at organizing stuff and well files are cluttered over my entire file system this makes tracking large files i don't need very difficult . Lots of application create a number of temporary files and these files also take significant amount of disk space and could be hard to track down if they are not created in /tmp .


The command I am discussing below helps you solve precisely this problem by giving you an ordered list (ordered in terms of size) of files and folders taking up space in your computer thus helping you find files/folder which are taking up significant amount of space :

du -sm *


Above command would display all the files and folder as well as their size as a list, however this is not a ordered list . To order the list we would need to pipe (that is send output of this command to another ) the output of the "du" command to "sort" command giving out list of files and folders sorted in ascending order according to the size.
du -sm * | sort -nr

Still there is a problem this is an entire list of files and folder in your file system , so if you have number of files and folders it will take number of screens to display . A better way would be to pipe the output of above command to "head" command to display only specified number of lines of output generated by "du -sm * | sort -nr " command .

du -sm *| sort -nr | head -15
Now the above command would display the top 15 files and folder according to their size .


Article Written by : Ambuj Varshney (blogambuj@gmail.com)
For Desktop on Linux Blog , http://linuxondesktop.blogspot.com
(C) 2008 , Ambuj Varshney

Comments

  1. It's probably worth mentioning that the output is in MB, not bytes.

    Initially my first thought on reading this was why not use "-h" and get it in, M, K, G depending, but when I tried it I realised that then the largest number, irrespective of unit, comes first so you could have: 688M, 500K, 4G in that order. Obviously when the list is long then you will miss many of the largest files...

    Thanks for the tip.

    ReplyDelete
  2. A better solution, in my opinion, would be to use the Disk Usage Analyser application in Ubuntu to drill down graphically. The only downside is that it takes a lot of time to start up.

    ReplyDelete
  3. I'm not sure about the way you have this command setup. From man du you can see that the -s flag just spits out a summary of everything without listing the files. If you just take out -s, this command works nicely.

    ReplyDelete

Post a Comment

Popular posts from this blog

13 Things to do immediately after installing Ubuntu

In this article i describe some of the things to do immediately after installing ubuntu on your machine . Since most of the people reading this would be shifting from Windows to Linux with a system dual booting so i would focus more on making transition easy from Windows to Linux.

Creating Your ultimate Ubuntu 7.10 Desktop

Ubuntu 7.10 Codenamed Gusty Gibbon was released few weeks back with much fanfare ,now Ubuntu for past couple of years has been one of the most popular Desktop Linux distributions . Ubuntu 7.10 includes a number of features , applets and Wizards to simplify desktop Linux experience however because of many licensing restrictions it does not include out of the box support for popular audio/video codecs and many commercial but good applications . Also because of the limitation of trying to accommodate all kind of applications on single CD Ubuntu comes with a limited set of applications .

Now , i often have arguments with my friends who are new to computers that windows is…

Over 16 Small Games For Ubuntu Linux

Over 16 Small Games For Ubuntu Linux

Ubuntu Linux is one of the most popular Linux distribution , it is especially popular among Linux newbies and windows refuges . Now Ubuntu Linux does come with a descent set of applications , still there is a scope for including some more quality applications and especially games . Now in this tutorial i will show you how to install a large number of small , easy and less resource hungry games on Ubuntu Linux with screen-shots of games .


1. Rocks 'n' Diamonds

Rocks 'n' Diamonds is a Boulderd*sh game for X11 with more than just the falling rocks and diamonds of its namesake. The object is still to collect all the diamonds (and emeralds), then get to the exit before time runs out. But your character must make use of bombs, spaceships, and many other elements in order to fill his quota of jewels.

Installation : -

Type the following command in the terminal window

wget http://www.artsoft.org/RELEASES/unix/rocksndiamonds/rocksndiamonds-3.2…

Making Music(Beats) on Linux/Ubuntu with Hydrogen

I am going to review a couple of Music Making Softwares for Linux and am starting with the simplest and one of the best!HYDROGEN. Hydrogen basically is a pattern based drum programming software which in layman terms means, it allows you to make your own beats.And in case you aren't much into music, you might be wondering “what the hell will i do with this piece of software”...well here is a word from my friends who've tried this: “Its pretty fun playing with this software, n even without knowing much, you could actually MAKE SUM MUSIC!!!”

There was this software called Acoustica Beatcraft(for windows) which actually introduced me to this beat making stuff and I was quite interested, but sadly it was too costly for me to buy it. So i was stuck using the trial version of the software and sadly as soon as i got the grip of the software the trial expired, and so my search began for software which would do the stuff for me and luckily i found this amazing piece of software HY…