LinuxQuestions.org
Help answer threads with 0 replies.
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 11-07-2011, 04:31 AM   #1
ghaedi591
LQ Newbie
 
Registered: Nov 2011
Posts: 28

Rep: Reputation: Disabled
oldest files will delete after reach to 21G


I want to delete the oldest files in a folder after reaching to 21Gig.
for this action i write the following code.
Dose it ok?
...
DUMP_DIR_SIZE_BEFOR=$(du -sm $ODP_PATH | awk '{print $1}')
while [DUMP_DIR_SIZE_BEFOR gt 21000]
do
rm "ls $ODP_PATH -lrt|tail -1"
DUMP_DIR_SIZE_BEFOR=$(du -sm $ODP_PATH | awk '{print $1}')
done

Narges.
 
Old 11-07-2011, 05:11 AM   #2
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
Maybe test :

Code:
find $ODP_PATH -size +21G | xargs rm
(do without "| xargs rm" before to be safe)

Last edited by Cedrik; 11-07-2011 at 05:14 AM.
 
0 members found this post helpful.
Old 11-07-2011, 05:52 AM   #3
ghaedi591
LQ Newbie
 
Registered: Nov 2011
Posts: 28

Original Poster
Rep: Reputation: Disabled
it seems that your code delete only the file which has 21G size but it is not my porpuse.
i want to delelte file from oldest to reach to less than 21G .
All of files in this directory are less than 1G.
 
Old 11-07-2011, 06:24 AM   #4
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
Ok, I get it

Use head rather than tail because tail will output newest files (last line of ls -lrt output)

Code:
DUMP_DIR_SIZE_BEFOR=$(du -sm $ODP_PATH | awk '{print $1}')

while [ "$DUMP_DIR_SIZE_BEFOR" -gt 21000 ]
do
    rm $(ls -rt $ODP_PATH | head -n1)
    DUMP_DIR_SIZE_BEFOR=$(du -sm $ODP_PATH | awk '{print $1}')
done

Last edited by Cedrik; 11-07-2011 at 06:37 AM.
 
1 members found this post helpful.
Old 11-07-2011, 09:11 AM   #5
ghaedi591
LQ Newbie
 
Registered: Nov 2011
Posts: 28

Original Poster
Rep: Reputation: Disabled
Angry

Thanx.Ur Reply was helpfull.
but it seems ".. du -sm... " is not working in my code!
what is wrong?
 
Old 11-07-2011, 10:20 AM   #6
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
I don't know... $ODP_PATH is set before in the script ?
Maybe check how $ODP_PATH is initialized
 
  


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
Creating a script that removes the oldest files on /tmp directory danndp Linux - Newbie 6 11-18-2010 09:47 AM
[ncftp] how to delete oldest directory and file using ncftp commands booyeeka Linux - Newbie 3 08-17-2010 11:23 AM
sort oldest 5 files in a directory tree recursively based on timestamp Linux abhelp Programming 1 06-04-2010 04:58 AM
delete oldest file in dir. by c program hitesh.sharma84 Linux - Kernel 1 05-02-2007 10:18 AM
Auto Delete oldest files @ratex when directory is 98% full jmanjohn61 Linux - Software 1 04-05-2005 03:44 PM

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

All times are GMT -5. The time now is 08:09 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