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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:47:11+00:00 2026-06-10T15:47:11+00:00

I am creating a simple script that will help my Ubuntu-Server manage my backups.

  • 0

I am creating a simple script that will help my Ubuntu-Server manage my backups. I compress my documents from my local machine every x-hours and scp it over to my backup machine. I want to have a maximum amount of backups that can stay in my backup directory. I am writing a script that will delete older backups if the maximum amount of backups have been reached. This is what I have so far, and it’s generating a file called MAX_backups when I run the script. Any ideas why this file is being created? I am very far from experienced when it comes to bash programming, but any help would be greatly appreciated. Thanks.

#!/bin/bash

backup_count=$(ls ~/backup | wc -w)

MAX_backups='750'

extra_count=$((backup_count - MAX_backups))

if [ backup_count > MAX_backups ]
then
        for ((i=0; i <= extra_count; i++))
        do
                file=$(ls ~/backup -t -r -1 | head --lines 1)
                rm ~/backup/"$file"
        done
fi
  • 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-06-10T15:47:13+00:00Added an answer on June 10, 2026 at 3:47 pm
    if [ backup_count > MAX_backups ]
    

    The > is being interpreted as a file redirection. Try one of these:

    # ((...)) is best for arithmetic comparisons. It is parsed specially by the shell and so a
    # raw `>` is fine, unlike within `[ ... ]` which does not get special parsing.
    if (( backup_count > MAX_backups ))
    
    # [[ ... ]] is a smarter, fancier improvement over single brackets. The arithmetic operator
    # is `-gt`, not `>`.
    if [[ $backup_count -gt $MAX_backups ]]
    
    # [ ... ] is the oldest, though most portable, syntax. Avoid it in new bash scripts as you
    # have to worry about properly quoting variables, among other annoyances.
    if [ "$backup_count" -gt "$MAX_backups" ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a script that I can run and it will simply ask
I'm creating a script on my main server and will use js/html to call
I'm creating a socket server that will run forever and push files out to
Trying to make a little script that will turn on server. I found few
I am having problems creating a simple PHP script. The $_GET[give] variable is always
I have simple table creating script in Postgres 9.1. I need it to create
I'm trying to write (what I thought would be) a simple bash script that
I'm creating a flash application that will post images to a url for saving
So im trying to find a script that can start me off with creating
I am creating a simple comparison script and I have some questions for the

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.