LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-13-2010, 12:38 PM   #1
Cerephim
Member
 
Registered: Mar 2005
Location: Dayton, Ohio
Distribution: CentOS
Posts: 49

Rep: Reputation: 0
keeping only the most recent 10 files


Hi folks,
I need a quick script that will help me keep only the most recent 10 files in a directory.

The files look something like this:
-rw-r----- 1 root root 34816 Dec 13 13:06 3_270_737318733.dbf
-rw-r----- 1 root root 709120 Dec 13 13:06 3_271_737318733.dbf
-rw-r----- 1 root root 63488 Dec 13 13:06 3_272_737318733.dbf
-rw-r----- 1 root root 316416 Dec 13 13:06 3_273_737318733.dbf
-rw-r----- 1 root root 113664 Dec 13 13:06 3_274_737318733.dbf
-rw-r----- 1 root root 479744 Dec 13 13:06 3_275_737318733.dbf
-rw-r----- 1 root root 411136 Dec 13 13:06 3_276_737318733.dbf
-rw-r----- 1 root root 7918592 Dec 13 13:06 3_277_737318733.dbf
-rw-r----- 1 root root 433152 Dec 13 13:06 3_278_737318733.dbf
-rw-r----- 1 root root 68096 Dec 13 13:06 3_279_737318733.dbf
-rw-r----- 1 root root 149504 Dec 13 13:06 3_280_737318733.dbf
-rw-r----- 1 root root 377856 Dec 13 13:06 3_281_737318733.dbf
-rw-r----- 1 root root 284160 Dec 13 13:06 3_282_737318733.dbf

I need to eliminate the older files, and keep only the most current.

I've done a ls -l | sort -r and written that to a file i can read into a loop. That's where i'm running into difficulty. The difficulty being, that I don't know how to keep only the most current 10 files.

Cerephim
 
Old 12-13-2010, 12:45 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

We just had a similar thread a little while ago, have a look here: Would like to delete all files in a directory except the 7 latest ones

Hope this helps.
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Recent files in XFCE niels.horn Slackware 12 05-04-2009 02:27 PM
Keeping people out of my files namit Linux - Security 6 10-04-2007 03:08 AM
Keeping ownership of files rtcary Linux - Newbie 2 07-17-2005 04:14 PM
find and move most recent files in dir backnine_99 Linux - Software 2 06-14-2005 12:03 PM
deleting recent files Santas Linux - General 2 01-19-2004 06:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:02 AM.

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