LinuxQuestions.org
Review your favorite Linux distribution.
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 07-21-2008, 05:03 AM   #1
investmentbnker75
Member
 
Registered: Oct 2007
Location: Eastern Seaboard
Distribution: CentOS
Posts: 162

Rep: Reputation: 15
Finding large files


I have a directory that keeps filling up and i need to clean it up. So i want to find large files i can possibly delete. I need a find command or shell script that will find large files over 500m and sort them with the largest at the top.

Im using one that isnt working very well:

#!/bin/bash
# if nothing is passed to the script, show usage and exit
[[ -n "$1" ]] || { echo "Usage: findlarge [PATHNAME]"; exit 0 ; }
# simple using find, $1 is the first variable passed to the script
find $1 -type f -size +520000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'

Thanks
 
Old 07-21-2008, 06:00 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,

You don't mention which problems you are experiencing. And I have to assume it has to do with files with spaces in them (your script otherwise works).

Maybe this will help, replace your find statement (including the pipe and awk) with:

find "$1" -type f -size +520000k -exec du -h {} \;

Instead of using ls and pipe all found to awk, it uses du (-h for human readability). The layout is a bit different then your script. Instead of
filename : 1Gb
it shows
1G filename

Hope this helps.
 
Old 07-21-2008, 06:16 AM   #3
nidsche
LQ Newbie
 
Registered: Jun 2008
Location: Germany
Posts: 21

Rep: Reputation: 16
Quote:
Originally Posted by investmentbnker75 View Post
I have a directory that keeps filling up and i need to clean it up. So i want to find large files i can possibly delete. I need a find command or shell script that will find large files over 500m and sort them with the largest at the top.

Im using one that isnt working very well:

#!/bin/bash
# if nothing is passed to the script, show usage and exit
[[ -n "$1" ]] || { echo "Usage: findlarge [PATHNAME]"; exit 0 ; }
# simple using find, $1 is the first variable passed to the script
find $1 -type f -size +520000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'

Thanks
How about trying

find $1 -type f -size +520000k -exec ls -l {} \; | awk '{ print $5 " " $9 }' | sort -nr

this will do a reverse numeric sort

BTW: don't forget that space is freed only when no more processes are accessing the file.
 
Old 07-21-2008, 05:57 PM   #4
FranDango
Member
 
Registered: Jun 2008
Posts: 101

Rep: Reputation: 15
Cleaning up by a script as an automated process is quite like betting on good luck. Why not find out where those unneeded large files do come from and what user or application is responsible for them? Would make more sense to me.

I would use 'du -h' and sort the results by file size with awk or something similar.

Linux Archive

Last edited by FranDango; 09-20-2008 at 05:50 AM.
 
  


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
LXer: This week at LWN: Large pages, large blocks, and large problems LXer Syndicated Linux News 0 09-27-2007 11:40 AM
Finding files and then finding content within those files... Maeltor Linux - Software 5 03-13-2007 12:06 PM
Finding the large files on a linux box antken Linux - General 1 08-31-2004 05:06 PM
Large Number of files? mikeshn Linux - Security 2 01-10-2004 06:11 AM
listing large files fintan Linux - Newbie 7 11-06-2003 11:40 AM

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

All times are GMT -5. The time now is 08:22 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration