Monday, June 3, 2013

Command Line Magic - See Data Usage In Linux

As we can see and sort our folders according to our requirement in windows, I was asking myself that is there any way that we can do that in linux ?

Then i searched a bit on 'opensource' internet world and I found one inbuilt linux command which is du.

du stands for Data Usage. But alone du command should not be used. I used du command along with head and sort command.

Command : du
    options used in du
           B -  B asks for buffer size, that either we want result in MB or KB.
Command : sort
    options used in sort:
           r - Reverse the result of comparisions
           n - Compare according to string numerical value
Command : head
    options used in head
           n - it decides how many results should be displayed.

Final Command made by using pipe

du -B M /root/ | sort -rn  | head -n 15

Here result will be showed in MB by reverse order as we used sort. It means highest usage folder will be displayed first and lowest will be the last. n's value in head is 15. It shows only 1st 15 results will be displayed.

No comments: