LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to find Top 10 Big files/Folder in the system? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-find-top-10-big-files-folder-in-the-system-883910/)

pinga123 06-01-2011 05:21 AM

How to find Top 10 Big files/Folder in the system?
 
Used following command to find out the top 10 big files in the system But it is having its own limitations as it consider files and directories both.
Code:

du -a / | sort -n -r | head -n 10
I would like to get the following information.

1)top 10 big files.
2)top 10 big directories.

File size with human readable output.
as executing
Code:

# du -a / | sort -n -r | head -n 10
5546667 /
2755464 /usr
2211844 /install
2136888 /install/linux-3.0-rc1
1508756 /usr/share
834836  /install/linux-3.0-rc1/drivers
716544  /usr/lib
365224  /lib
331924  /lib/modules
317132  /usr/share/locale

Giving me correct output
but when i add -h option for human readable file size its giving me wrong output.
Confused why its happening any clue?
Code:

# du -ha / | sort -n -r | head -n 10
1020K  /lib/modules/3.0.0-rc1/kernel/drivers/net/e1000/e1000.ko
1020K  /install/linux-3.0-rc1/drivers/net/e1000/e1000.ko
1016K  /usr/src/kernels/2.6.18-92.el5-i686/scripts/kconfig
1016K  /usr/share/system-config-selinux
1016K  /usr/lib/perl5/5.8.8/i386-linux-thread-multi/auto/Encode/TW
1016K  /lib/modules/3.0.0-rc1/kernel/sound/core/snd.ko
1016K  /lib/modules/3.0.0-rc1/kernel/drivers/net/tulip/tulip.ko
1016K  /install/linux-3.0-rc1/sound/core/snd.ko
1016K  /install/linux-3.0-rc1/drivers/net/tulip/tulip.ko
1012K  /usr/lib/python2.4/distutils/command


bornforlinux 06-01-2011 05:39 AM

You ca also give below command

du -sh *|grep M|more

or

du -sh *|grep G|more

G for files which are in gigabytes and M for file in megabytes

pinga123 06-01-2011 05:48 AM

Quote:

Originally Posted by bornforlinux (Post 4372918)
You ca also give below command

du -sh *|grep M|more

or

du -sh *|grep G|more

G for files which are in gigabytes and M for file in megabytes

You are not sorting the output here.
Anyway thanks for sharing.

crts 06-01-2011 05:59 AM

Hi,

try this:
Code:

du -ha / | sort -h -r | head -n 10
HTH

pinga123 06-01-2011 06:04 AM

Quote:

Originally Posted by crts (Post 4372932)
Hi,

try this:
Code:

du -ha / | sort -h -r | head -n 10
HTH

Code:

# du -ha / | sort -h -r
sort: invalid option -- h
Try `sort --help' for more information.


crts 06-01-2011 06:17 AM

Quote:

Originally Posted by pinga123 (Post 4372937)
Code:

# du -ha / | sort -h -r
sort: invalid option -- h
Try `sort --help' for more information.


Which version of sort are you using? Here is mine
Code:

$ sort --version
sort (GNU coreutils) 8.5
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and Paul Eggert.

And what is the output of
Code:

sort --help

salasi 06-01-2011 07:12 AM

Quote:

Originally Posted by pinga123 (Post 4372905)
but when i add -h option for human readable file size its giving me wrong output.
Confused why its happening any clue?
Code:

# du -ha / | sort -n -r | head -n 10
1020K  /lib/modules/3.0.0-rc1/kernel/drivers/net/e1000/e1000.ko
1020K  /install/linux-3.0-rc1/drivers/net/e1000/e1000.ko
1016K  /usr/src/kernels/2.6.18-92.el5-i686/scripts/kconfig
1016K  /usr/share/system-config-selinux
1016K  /usr/lib/perl5/5.8.8/i386-linux-thread-multi/auto/Encode/TW
1016K  /lib/modules/3.0.0-rc1/kernel/sound/core/snd.ko
1016K  /lib/modules/3.0.0-rc1/kernel/drivers/net/tulip/tulip.ko
1016K  /install/linux-3.0-rc1/sound/core/snd.ko
1016K  /install/linux-3.0-rc1/drivers/net/tulip/tulip.ko
1012K  /usr/lib/python2.4/distutils/command


Briefly, sort is not a human. If you want sort to sort correctly, you have to feed it data in a form that it can work with. It doesn't know that, in this context, a K is worth 1000 (or is it 1024?) of not-a-suffix counts, and that an M is worth 1000 (or 1024) K counts.

The simplest thing is to stick with the non-human-readable form, but, if you really wanted you could
  • look at the 'G's first, count them, subtract from the total, move on to the 'M's, etc
  • work on the numbers in n-h-r form and convert them at the end (easier if k=1000, etc), for the human to read
neither of the above seem worth the effort, to me, but YMMV

pinga123 06-01-2011 11:06 PM

Quote:

Originally Posted by crts (Post 4372949)
Which version of sort are you using? Here is mine
Code:

$ sort --version
sort (GNU coreutils) 8.5
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and Paul Eggert.

And what is the output of
Code:

sort --help

Code:

# sort --version
sort (GNU coreutils) 5.97
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and Paul Eggert.


crts 06-02-2011 07:01 AM

Quote:

Originally Posted by pinga123 (Post 4373732)
Code:

# sort --version
sort (GNU coreutils) 5.97
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

Written by Mike Haertel and Paul Eggert.


Well, you are using a very old version of sort. Apparently sort did not have the '-h' option back then. Any chance that you can upgrade to the latest version?

pinga123 06-03-2011 12:41 AM

Quote:

Originally Posted by crts (Post 4374028)
Well, you are using a very old version of sort. Apparently sort did not have the '-h' option back then. Any chance that you can upgrade to the latest version?

It will then make the script not so general .
However I would love to update it to latest version.Any idea on how do i do it?

crts 06-03-2011 02:15 AM

Quote:

Originally Posted by pinga123 (Post 4374751)
It will then make the script not so general .
However I would love to update it to latest version.Any idea on how do i do it?

Well, that depends on which system you are using. Normally your update-manager should keep it up to date. If this is not the case then *maybe* newer versions are not compatible with your system.


All times are GMT -5. The time now is 06:44 AM.