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
|