Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 677341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:01:44+00:00 2026-05-14T01:01:44+00:00

I have a directory where our deployments go. A deployment (which is itself a

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:01:44+00:00Added an answer on May 14, 2026 at 1:01 am

    A quick one-liner:

    ls | sed 's/_[0-9]\{8\}$//' | uniq |
    while read name; do
        rm $(ls -r ${name}* | tail -n +2)
    done
    

    List the files, chop off an underscore followed by eight digits, only keep unique names. For each name, remove everything but the most recent.

    Assumptions:

    • the most recent will be last when sorted alphabetically. If that’s not the case, add a sort that does what you want in the pipeline before tail -n +2
    • no other files in this directory. If there are, limit the output of the ls, or pipe it through a grep to select only what you want.
    • no weird characters in the filenames. If there are… instead of directly using the output of the inner ls pipeline, you’d probably want to pipe it into another while loop so you can quote the individual lines, or else capture it in an array so you can use the quoted expansion.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In our web application we have a directory which resides outside of the project.
We have a .NET application which our customers consider too large for mass deployment
Within our Active Directory domain, we have a MS SQL 2005 server, and a
I need to do a Bin deployment on our ISP, Network Solutions. They have
We have a protected directory on our site, where users are required to login
Is there an exec variant that will use the current application directory to locate
We have a huge ASP.NET web application which needs to be deployed to LIVE
I have a directory that is in our svn repository. On my local system,
We have a standard MSBuild project file that is used for our different deployment
In my current project we have directory with all of our third party (jQuery,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.