Hello Forum.
I have the following files in one directory:
abc_july01_2013.txt
abc_july02_2013.txt
abc_july03_2013.txt
abc_july04_2013.txt
abc_july05_2013.txt
abc_july06_2013.txt
abc_july07_2013.txt
abc_july08_2013.txt
If I want to be able to keep the last 5 versions of the file and delete the rest so that all that remains is:
abc_july04_2013.txt
abc_july05_2013.txt
abc_july06_2013.txt
abc_july07_2013.txt
abc_july08_2013.txt
Then the following code will accomplish this:
rm -f `ls -tp abc* | grep -v "/$" | awk '{ if (NR > 5) print; }'`
But I don't want to hard-code the # of versions (which is 5 in this case). I want to be able to pass in a parameter value to the command so that it's more flexible. Is there an easy way that it can be done?
Thanks