The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
shell script to delete directories... Stephan Shell Programming and Scripting 5 05-16-2008 05:11 AM
How to delete files in UNIX using shell script theguy16 Shell Programming and Scripting 7 04-09-2008 01:40 AM
script to delete files vats Shell Programming and Scripting 12 09-01-2007 02:27 AM
Need Help: Delete a file by Shell Script r3edi Shell Programming and Scripting 5 07-11-2005 04:13 AM
how to delete empty files in a shell script rpnuge UNIX for Advanced & Expert Users 1 07-11-2002 01:56 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-07-2006
Registered User
 

Join Date: Jul 2006
Posts: 4
Exclamation shell script for delete old files

i want to delete all the files in my directory except the latest one. i need to do this from shell script.
say i have
a.txt - latest file
b.txt,
c.txt..
it should delete all the files except a.txt?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-07-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,643
Code:
file=$(ls -tr | tail -1)
find . ! -newer "$file" -maxdepth 1 -exec rm {} \;
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:49 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0