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
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
getting the most recent file anujairaj Shell Programming and Scripting 3 06-22-2006 12:34 PM
delete files except most recent ST2000 Shell Programming and Scripting 5 06-21-2005 11:33 AM
Recent Changes To Forum ... Cameron Post Here to Contact Site Administrators and Moderators 2 03-08-2002 06:57 PM

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

Join Date: Jun 2006
Posts: 37
Stumble this Post!
To keep only the most recent files

Hi all,

I'm running on a Sun Solaris machine. I would only want to keep the last 2 most recent files on 1 of my directory.

Below shows my script, but it is incomplete. For the ?? part I do not know how to continue. please help

DIR=/tmp/abc
OUTPUT=/tmp/output.out
OUTPUT1=/tmp/output1.out

cd $DIR
ls -rt | tail -2 > $OUTPUT
ls > $OUTPUT1
cat $OUTPUT1 | while read archive
do
if [ "$archive" = ?? ]; then
echo "Keeping ..."
else
rm $archive
fi
done

Thank you.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 07-26-2007
Registered User
 

Join Date: Jun 2006
Posts: 37
Stumble this Post!
Issue solved.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:50 PM.


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