Logo 
Search:

Unix / Linux / Ubuntu Answers

Ask Question   UnAnswered
Home » Forum » Unix / Linux / Ubuntu       RSS Feeds
  on Dec 26 In Unix / Linux / Ubuntu Category.

  
Question Answered By: Adah Miller   on Dec 26

Well, if you don't mind a quick and dirty inefficient program, here's
something that I think does what you want. You cd into the top of the
directory tree you want to look at, for example "cd /home/abc".
Then run it "find_big_files.pl > /tmp/log_file". The results should be
dumped into the log file. Of course, you have to put find_big_files.pl
somewhere on your $PATH

It's very slow to output anything if you run it in a directory that
has many files/subdirectories. If you cd into / and run it, better
plan to leave it overnight, and I can't speak for how much memory it
might use.

It may have bugs, I wrote it about as fast as I could type. For the
same reason, it's not very efficient.

But it does seem to work.

Feel free to improve and/or share it, under any version of the GPL you prefer.

I'll bet that after I post this, someone will come up with a one-liner
solution. :-)

#!/usr/bin/perl

# find_big_files.pl
#
# abc 5/2008

use warnings;
use strict;

$|++;

my ($in_pipe);
my ($current_line);
my (%file_hash);
my ($key);
my ($entry);

unless (open ($in_pipe, "/usr/bin/find . -exec /bin/ls -ld {} \\; |"))
{
die "***ERROR*** Could not open pipe from find command, $!\n";
}

while ($current_line = <$in_pipe>)
{
chomp ($current_line);

$key = (split (/\s+/, $current_line))[4];


if ($key)
{
push @{$file_hash{$key}}, $current_line;
}
}

foreach $key (sort {$b <=> $a} keys %file_hash)
{
foreach $entry (@{$file_hash{$key}})
{
print "$entry\n";
}
}

close ($in_pipe);

Share: 

 

This Question has 14 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Finding largest file Or get search suggestion and latest updates.


Tagged: