On Tuesday 13 October 2009, Jeff D wrote: > On Tue, 13 Oct 2009, Israel Garcia wrote: > > Hi List, > > > > It's a simple question but difficult to me :-). > > > > How can I delete all files on a folder /xxxx but keeping only the > > two latest (newest) files? > > how about something like this to start: > for file in $(ls -tA | egrep -v "$(ls -tA |head -n 2)") ; do if [ -f > $file ] ; then echo "do a rm of $file" ;fi ; done >
How about rm `ls --sort=time | sed '1,2d'` ? -Chris ------------------------------------------------------------------------ | Christopher Judd, Ph. D. | | Research Scientist III | | NYS Dept. of Health j...@wadsworth.org | | Wadsworth Center - ESP | | P. O. Box 509 518 486-7829 | | Albany, NY 12201-0509 | ------------------------------------------------------------------------ IMPORTANT NOTICE: This e-mail and any attachments may contain confidential or sensitive information which is, or may be, legally privileged or otherwise protected by law from further disclosure. It is intended only for the addressee. If you received this in error or from someone who was not authorized to send it to you, please do not distribute, copy or use it or any attachments. Please notify the sender immediately by reply e-mail and delete this from your system. Thank you for your cooperation. -- To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org