Possible Duplicate:
Delete all but the most recent X files in bash
The scenerio is as follows:
Two tar files will be created in one directory per day, but I need only the latest two files, so how to delete the other files automatically each day?
Is i possible to write this script using pure shell commands, and not with high level language such as perl, python or ruby...
This issue is a bit similar to FTP - Only want to keep latest 10 files - delete LRU and how to delete all files except the latest three in a folder
but mine also needs to test if a tar file is corrupt
If newer tar file is corrupt, I would not keep it, but reserve the older ones, so what the script should be like?