![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How do you list the most recent files writen to a volume | williamhsman | OS X (Apple) | 1 | 10-12-2007 09:19 AM |
| Get Files from ftp which are uploaded recent week | narramadan | Shell Programming and Scripting | 1 | 09-27-2007 05:05 AM |
| To keep only the most recent files | *Jess* | Shell Programming and Scripting | 1 | 07-26-2007 08:11 PM |
| when I try to run rm on multiple files I have problem to delete files with space | umen | UNIX for Dummies Questions & Answers | 1 | 09-20-2005 12:20 AM |
| I can't delete some files | DISTURBED | UNIX for Dummies Questions & Answers | 4 | 08-01-2002 08:15 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
delete files except most recent
#!/bin/ksh -xvf
for arch_filename in `ls -lrt /u02/oracle/CMDR/archive | awk '{print $9}'`; do echo "rm -rf /u02/oracle/CMDR/archive/"$arch_filename rm -rf /u02/oracle/CMDR/archive/$arch_filename done I am running the above shell script every 10 minutes. I need to not delete the most recent file, but delete everything else. Each file is 500 mb. How would I do it. Basically when job kicks off, some files are getting deleted as it is writing the archive log and system is getting filled up and I cant see where the files are written to. I have to bounce the box to see the space. This is linux box. Thanks, ST2000 |
| Forum Sponsor | ||
|
|
|
|||
|
Code:
DIR=/u02/oracle/CMDR/archive find $DIR -type f -maxdepth 1 -printf "%T@\t%p\n" | #list files with timestamps sort -k1,1n | #sort oldest -> newest cut -f2- | #remove timestamps sed '$d' | #remove the last one (newest file) tr '\n' '\0' | #delimit with NULs in case spaces in names xargs -r0 rm -f |
|
|||
|
Quote:
|
|
|||
|
Thanks for all the posts.
Each file is about 500mb. If the delete job kicks off and if there is a file written at that time, linux does not know what to do and locks that space off. Say 200 mb is written when delete kicks off, that 200mb is gone from archive filesystem and in a week's time it reduces to nothing and will not last even an hour. I have to bounce db to clear up pending archives. Instead i want a modification to my script to preserve the last file and delete all. Anyway i modified the script adding a variable which greps for last file and delete using grep -v of that last file. It was just one more line to my existing script. Thanks again |
|||
| Google The UNIX and Linux Forums |