Solved

Linux script or command to read top 50 file size

Posted on 2014-09-09
7
318 Views
Last Modified: 2014-09-10
Dear Experts,

Since my disk-space is used more than 95%, Could you provide  linux
command or script to find out the top 50 biggest files size in my hard-disk so that I can delete those
not-important files with bigger file size. I check du and df command not including that .

Please advise
0
Comment
Question by:rwniceing
  • 4
  • 3
7 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 40313773
ls -sR / | perl -MHeap::Simple -lne 'BEGIN{ $heap = Heap::Simple->new(elements => "Array")}m#^(/.*):# and $d=$1; m/^(\d+)\s+(.*)/ and $heap->insert([$1,"$d/$2"]) and print "$1 $d/$2"; $heap->count>50 and $heap->extract_top;END{print "@$_" for  $heap->extract_all;} '
0
 
LVL 1

Author Comment

by:rwniceing
ID: 40313798
ozo, thanks for your reply. I get this error on linux Centos when run the command  on linux shell
Can't locate Heap/Simple.pm in @INC (@INC contains: /usr/local/lib/perl5/site_perl/5.16.2/x86_64-linux /usr/local/lib/perl5/site_perl/5.16.2 /usr/local/lib/perl5/5.16.2/x86_64-linux /usr/local/lib/perl5/5.16.2 .).
BEGIN failed--compilation aborted.
0
 
LVL 1

Author Comment

by:rwniceing
ID: 40313800
Or do I need to run it in script with including perl ?
0
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 40313808
You could install it, or use a slightly less efficient method:
ls -sR / | perl -lne 'm#^(/.*):# and $d=$1; m/^(\d+)\s+(.*)/ and print "$1 $d/$2"' | sort -n | tail -50
0
 
LVL 1

Author Comment

by:rwniceing
ID: 40313815
it works but including  all directory from root , how can I  just do it  for my account directory  such as "/home/myaccount" ?
0
 
LVL 84

Expert Comment

by:ozo
ID: 40313830
ls -sR /home/myaccount
0
 
LVL 1

Author Closing Comment

by:rwniceing
ID: 40313837
thanks for your rely ,now I know what  you mean  and following command works

ls -sR /home/myaccount | perl -lne 'm#^(/.*):# and $d=$1; m/^(\d+)\s+(.*)/ and print "$1 $d/$2"' | sort -n | tail -50
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now