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

The Archive Base Latest Questions

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

I need to automate a clean-up of a Linux based FTP server that only

  • 0

I need to automate a clean-up of a Linux based FTP server that only holds backup files.

In our “\var\DATA” directory is a collection of directories. Any directory here used for backup begins with “DEV”. In each “DEVxxx*” directory are the actual backup files, plus any user files that may have been needed in the course of maintenance on these devices.

We only want to retain the following files – anything else found in these “DEVxxx*” directories is to be deleted:

The newest two backups:  ls -t1 | grep -m2 ^[[:digit:]{6}_Config]  
The newest backup done on the first of the month:  ls -t1 | grep -m1 ^[[:digit:]{4}01_Config] 
Any file that was modified less than 30 days ago:  find -mtime -30  
Our good configuration file:  ls verification_cfg

Anything that doesn’t match the above should be deleted.

How can we script this?

I’m guessing a BASH script can do this, and that we can create a cron job to run daily to perform the task.

  • 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-11T22:10:04+00:00Added an answer on June 11, 2026 at 10:10 pm

    For what it’s worth, here is the bash script I created to accomplish my task. Comments are welcome.

    #!/bin/bash
    
    # This script follows these rules:
    #
    #  - Only process directories beginning with "DEV"
    #  - Do not process directories within the device directory
    #  - Keep files that match the following criteria:
    #     - Keep the two newest automated backups
    #     - Keep the six newest automated backups generated on the first of the month
    #     - Keep any file that is less than 30 days old
    #     - Keep the file "verification_cfg"
    #
    #  - An automated backup file is identified as six digits, followed by "_Config"
    #    e.g.  20120329_Config
    
    
    # Remember the current directory
    CurDir=`pwd`
    
    # FTP home directory
    DatDir='/var/DATA/'
    cd $DatDir
    
    # Only process directories beginning with "DEV"
    for i in `find . -type d -maxdepth 1 | egrep '\.\/DEV' | sort` ; do
     cd $DatDir
    
     echo Doing "$i"
     cd $i
    
     # Set the GROUP EXECUTE bit on all files
     find . -type f -exec chmod g+x {} \;
    
     # Find the two newest automated config backups
     for j in `ls -t1 | egrep -m2 ^[0-9]{8}_Config$` ; do
      chmod g-x $j
     done
    
     # Find the six newest automated config backups generated on the first of the month
     for j in `ls -t1 | egrep -m6 ^[0-9]{6}01_Config$` ; do
      chmod g-x $j
     done
    
     # Find all files that are less than 30 days old
     for j in `find -mtime -30 -type f` ; do
      chmod g-x $j
     done
    
     # Find the "verification_cfg" file
     for j in `find -name verification_cfg` ; do
      chmod g-x $j
     done
    
     # Remove any files that still have the GROUP EXECUTE bit set
     find . -type f -perm -g=x -exec rm -f {} \;
    
    done
    
    # Back to the users current directory
    cd $CurDir
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to automate a process that involves getting data from a series of
I need to automate R to read a csv datafile that's into a zip
I need to automate the migration from an Access (2003) to an SQL Server
I have an application that I need to automate where at a certain time
I need to automate a SoapUI-project that uses HermesJMS with Maven2. The Problem I
I need to automate a process involving a website that is using a login
I need to automate a particular task that involves: Fetching mails from my mailbox
I have the need to automate conversion of html files into MS Word files,
In my project, I need to automate Excel and Word at the server side
I need to automate the following command cmd=yes | vgremove <vgname> whenever I code

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.