LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-15-2009, 05:45 PM   #1
phani.junk1
LQ Newbie
 
Registered: Oct 2009
Posts: 10

Rep: Reputation: 1
Shell script to delete old files whenever storage limit is crossed


Hi

I am looking for a shell script to delete old files whenever storage limit is crossed for a folder. That would be great if anyone point me in the right direction in finding a simple way to do this?

Thanks in advance
 
Old 10-15-2009, 07:12 PM   #2
WhisperiN
Member
 
Registered: Jun 2009
Location: Middle East
Distribution: Slackware 13.1, CentOS 5.5
Posts: 137

Rep: Reputation: 17
Hello there :-)

Can you please provide more information about the place that you want these files be deleted from?

For example, do you need the script to delete files form a specific folder or what's exactly the point?


Thanks.
 
Old 10-15-2009, 11:57 PM   #3
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by phani.junk1 View Post
Hi

I am looking for a shell script to delete old files whenever storage limit is crossed for a folder. That would be great if anyone point me in the right direction in finding a simple way to do this?

Thanks in advance
Here is the right direction:

1. Write a script that has a way to determine that a specified storage limit is exceeded.

2. If (1) is true, locate the oldest files and delete them.

Start coding and if you have difficulties, show us your code.
 
Old 10-16-2009, 03:03 AM   #4
phani.junk1
LQ Newbie
 
Registered: Oct 2009
Posts: 10

Original Poster
Rep: Reputation: 1
deleting files from a folder whenever limit is crossed

Quote:
Originally Posted by WhisperiN View Post
Hello there :-)

Can you please provide more information about the place that you want these files be deleted from?

For example, do you need the script to delete files form a specific folder or what's exactly the point?


Thanks.
Hi

Thanks for a reply. This is my scenario i am trying for
Initially i am looking to delete files from specific folder whenever limit is crossed by using shell script and when i am done with that i will try to do it on the email messages
 
Old 10-16-2009, 07:25 AM   #5
WhisperiN
Member
 
Registered: Jun 2009
Location: Middle East
Distribution: Slackware 13.1, CentOS 5.5
Posts: 137

Rep: Reputation: 17
Alright..
Great, Please, issue this command and give back the result.. tell us which part of your HDD you want to monitor.

Code:
# df -h
Also, please tell if you want the react be taken looking at the over all percentage (Use %) or looking at the available capacity.

I'll try my best to help you :-)

Regards..
 
Old 10-16-2009, 11:01 AM   #6
phani.junk1
LQ Newbie
 
Registered: Oct 2009
Posts: 10

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by WhisperiN View Post
Alright..
Great, Please, issue this command and give back the result.. tell us which part of your HDD you want to monitor.

Code:
# df -h
Also, please tell if you want the react be taken looking at the over all percentage (Use %) or looking at the available capacity.

I'll try my best to help you :-)

Regards..
I got this output as below

Filesystem Size Used Avail Use% Mounted on
/dev/sda3 11G 7.8G 2.0G 81% /
/dev/sda2 11G 158M 9.5G 2% /home
/dev/sda1 1.1G 24M 936M 3% /boot
tmpfs 778M 0 778M 0% /dev/shm
/dev/md0 112M 5.8M 100M 6% /raid

i got a folder named oldfiles that is in my home directory so can monitor any part like /dev/sda3 by looking at the available capacity
 
Old 10-19-2009, 11:14 AM   #7
Deviathan
Member
 
Registered: Dec 2005
Posts: 52

Rep: Reputation: 18
You could probably use the "du -s $FOLDERNAME" command and check to see if a certain size has been reached then use the following find command:

find $FOLDERNAME -mtime $DAYS -exec rm -f {} \;

$FOLDERNAME is the full pathname to your folder and $DAYS would be how long ago the file was last modified.

So in a script you would just check the value returned from running `du -s $FOLDERNAME`. The return value is in kilobytes usually I think so keep that in mind. Then execute the find command if your condition returns true.

This should be a pretty simple script to implement.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script to automatically delete files with the same name as the parent directory pratap.iisc Programming 9 10-12-2009 10:17 AM
How to delete lines and insert another line in some xml files using a shell script? luananeko Linux - Newbie 1 07-20-2009 09:53 PM
How to create/delete temp/backup files through a shell script ? Sid2007 Programming 4 10-17-2007 01:55 PM
shell script to compare filese b/w local and remote and delete files from local serve dsids Linux - Networking 9 08-23-2006 07:20 AM
Making shell script to 'locate' m4a files and delete them bd1308 Linux - Software 3 02-12-2006 10:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:19 AM.

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