Hello, I’m looking to write a shell script that performs what I believe to be very rudimentary clean-up of a directory. I’ve been searching and trying several different techniques but as a very novice shell programmer, am still having trouble.
What I’m trying to do is write a script to look for the number of files that exist in a directory. If the number exceeds X then I want the script to delete the excess by date (oldest). For example:
[$ls]
file1
file2
file3
file4
If the output quantity is more than 2, I’m looking to delete the excess older files. If the output is 2 or less then I want nothing to be done. I have another automated process that continues to roll these files out and plan to call this script via cron to continually delete the excess and retain the most recent two files.
All comments and feedback is appreciated…
