Tar files get stored in a directory with name in the following format
I need to write a script which when run should keep only the latest 3 versions of the file and delete the other versions. This could be achieved by reading the date and time form the tar name. But how to determine which ones are the latest 3 versions.
Could anyone please help me regarding the problem?
Think before you speak as you might hurt or break someone's heart.
If you can rely on the file's own filesystem date, the output of "ls -l[r]t" can be used. Something like:
ls -lrt | tail -l -3 | xargs rm
WARNING: Major corrections probably required.
I prefer my naming conventions to be more in the line of "fileYYYYMMDD.tar.gz" myself. Not only can you use a simple sort, it avoids confusion about American/English date formats (MM/DD/YY vs. DD/MM/YY) - not to mention other countries. Named months are not well-suited for date arithmetic, even when international issues don't figure in.
Customer surveys are for companies who didn't pay proper attention to begin with.