bondtrails
Technical User
Hello all!
I am new to unix scripting and I am trying to learn a few things by writing in unix scripts utility programs I wrote in other languages. Here is where I am currently stumped:
I would like to delete files older than "X" generations. By that I mean if in a given directory there are 10 files (for arguments sake) and I want my script to keep only the first 3 files and delete all other files (therefore deleting files "older" than 3 generations), how would it be done? Note that the file names will always follow a specific format: YYYYMMDD_HHMNSS_FILENAME.txt
I've seen the other posts that use "find <dir> -type f -mtime DD -exec rm {}\;" command but as far as I can tell, this function depends on the number of days DD and not specifically on the broader case of number of generations.
Thank you for any help or direction you can provide!
--Bondster!
I am new to unix scripting and I am trying to learn a few things by writing in unix scripts utility programs I wrote in other languages. Here is where I am currently stumped:
I would like to delete files older than "X" generations. By that I mean if in a given directory there are 10 files (for arguments sake) and I want my script to keep only the first 3 files and delete all other files (therefore deleting files "older" than 3 generations), how would it be done? Note that the file names will always follow a specific format: YYYYMMDD_HHMNSS_FILENAME.txt
I've seen the other posts that use "find <dir> -type f -mtime DD -exec rm {}\;" command but as far as I can tell, this function depends on the number of days DD and not specifically on the broader case of number of generations.
Thank you for any help or direction you can provide!
--Bondster!