LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-01-2011, 05:21 AM   #1
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Rep: Reputation: 37
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
 
Old 06-01-2011, 05:39 AM   #2
bornforlinux
LQ Newbie
 
Registered: May 2011
Posts: 6

Rep: Reputation: Disabled
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
 
Old 06-01-2011, 05:48 AM   #3
pinga123
Member
 
Registered: Sep 2009
Posts: 684

Original Poster
Blog Entries: 2

Rep: Reputation: 37
Quote:
Originally Posted by bornforlinux View Post
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.
 
Old 06-01-2011, 05:59 AM   #4
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Hi,

try this:
Code:
du -ha / | sort -h -r | head -n 10
HTH
 
Old 06-01-2011, 06:04 AM   #5
pinga123
Member
 
Registered: Sep 2009
Posts: 684

Original Poster
Blog Entries: 2

Rep: Reputation: 37
Quote:
Originally Posted by crts View Post
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.
 
Old 06-01-2011, 06:17 AM   #6
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by pinga123 View Post
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
 
Old 06-01-2011, 07:12 AM   #7
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Quote:
Originally Posted by pinga123 View Post
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
 
Old 06-01-2011, 11:06 PM   #8
pinga123
Member
 
Registered: Sep 2009
Posts: 684

Original Poster
Blog Entries: 2

Rep: Reputation: 37
Quote:
Originally Posted by crts View Post
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.
 
Old 06-02-2011, 07:01 AM   #9
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by pinga123 View Post
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?
 
Old 06-03-2011, 12:41 AM   #10
pinga123
Member
 
Registered: Sep 2009
Posts: 684

Original Poster
Blog Entries: 2

Rep: Reputation: 37
Quote:
Originally Posted by crts View Post
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?
 
Old 06-03-2011, 02:15 AM   #11
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by pinga123 View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use Big O, Big Omega, and Big Theta to find running time of algorithms naveed17 Programming 3 03-17-2011 10:25 AM
How to find big files on the disk? hadimotamedi Linux - Newbie 2 10-17-2010 06:38 AM
root partition full but cannot find big files leotina Linux - Newbie 3 09-01-2009 11:19 PM
Find big files markvc Linux - General 4 12-05-2006 07:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration