bash script to delete old deployments

Posted by benjwarner on Stack Overflow See other posts from Stack Overflow or by benjwarner
Published on 2010-03-23T21:57:01Z Indexed on 2010/03/23 22:13 UTC
Read the original article Hit count: 348

Filed under:

I have a directory where our deployments go. A deployment (which is itself a directory) is named in the format:

<application-name>_<date>

e.g. trader-gui_20091102

There are multiple applications deployed to this same parent directory, so the contents of the parent directory might look something like this:

trader-gui_20091106
trader-gui_20091102
trader-gui_20091010
simulator_20091106
simulator_20091102
simulator_20090910
simulator_20090820

I want to write a bash script to clean out all deployments except for the most current of each application. (The most current denoted by the date in the name of the deployment). So running the bash script on the above parent directory would leave:

trader-gui_20091106
simulator_20091106

Any help would be appreciated.

© Stack Overflow or respective owner

Related posts about bash