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 7623217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:39:04+00:00 2026-05-31T04:39:04+00:00

Firstly, I’m completely lost when it comes to shell scripting so I’m expecting a

  • 0

Firstly, I’m completely lost when it comes to shell scripting so I’m expecting a fairly easy solution to this. I just don’t know where to find it.

The situation is this: We are running an application from which we take backups (duh!). The application comes with it’s own backup script which when run creates a folder with the current date and time as name. Within these are a database dump and some config files like such:

# cd backup
# ll
drwxr-xr-x 2 root root 4096 Mar  6 02:30 2012-03-06_02-15 
# ll 2012-03-06_02-15
-rw-r--r-- 1 root root   26706579 Mar  6 02:16 Application.tar.gz
-rw-r--r-- 1 root root      26060 Mar  6 02:15 Config.tar.gz
-rw-r--r-- 1 root root 5503574530 Mar  6 02:21 DatabaseBackup.sql.gz

The backup folder is then rsync’d to a network drive.

The script also allows an argument for the number of days backup to keep. Which is great. But now we’re starting to see concerns with disk space on the production server.

Replicating the scripts functionallity to dump the database and compress the configs isn’t a problem.

But where I get lost is here: I would ideally like to keep the latest backup on the production server, and keep X backups on the network drive.

I’m thinking this shouldn’t be too hard using bash (or maybe expect?)

  • 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-31T04:39:05+00:00Added an answer on May 31, 2026 at 4:39 am

    The following will delete everything except the most recent item in a directory:

    ls -lrt | grep -v total | awk '{print $9}' | head -n -1 | xargs rm 
    

    If you require X number of remaining items you can alter head -n -1 to head -n -X

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly, I just want to say that the gmaps4rails gem has been fantastic. Easy
Firstly: I am totally a newbie for this kind of work. I have a
Firstly I know that there are many question and solutions to correct thread marshalling
Firstly, I do not have any malicious intent out of this question. I would
Firstly, I'm not using rails. This is vanilla ruby application. I've read about packaging
Firstly I realise that this is a familiar question, it seems to pop up
Firstly, this is a homework assignment, and I am very new to programming in
Firstly, let me say that I've been on this issue for pretty much 2
Firstly, YES, this is a duplicate issue that's been asked 100 times on here,
Firstly, I apologise if this is a dupe - I suspect it may be

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.