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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:14:08+00:00 2026-06-08T13:14:08+00:00

I had previously used a simple find command to delete tar files not accessed

  • 0

I had previously used a simple find command to delete tar files not accessed in the last x days (in this example, 3 days):

find /PATH/TO/FILES -type f -name "*.tar" -atime +3 -exec rm {} \;

I now need to improve this script by deleting in order of access date and my bash writing skills are a bit rusty. Here’s what I need it to do:

  1. check the size of a directory /PATH/TO/FILES
  2. if size in 1) is greater than X size, get a list of the files by access date
  3. delete files in order until size is less than X

The benefit here is for cache and backup directories, I will only delete what I need to to keep it within a limit, whereas the simplified method might go over size limit if one day is particularly large. I’m guessing I need to use stat and a bash for loop?

  • 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-08T13:14:10+00:00Added an answer on June 8, 2026 at 1:14 pm

    Here’s a simple, easy to read and understand method I came up with to do this:

    DIRSIZE=$(du -s /PATH/TO/FILES | awk '{print $1}')
    if [ "$DIRSIZE" -gt "$SOMELIMIT" ]
      then
        for f in `ls -rt --time=atime /PATH/TO/FILES/*.tar`; do
        FILESIZE=`stat -c "%s" $f`
        FILESIZE=$(($FILESIZE/1024))
    
        DIRSIZE=$(($DIRSIZE - $FILESIZE))
        if [ "$DIRSIZE" -lt "$LIMITSIZE" ]; then
            break
        fi
    done
    fi
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking into development standards fro JavaScript. I had previously used Doulgas Crockfords Javascript
I previously had a post on this issue that was resolved. However since rebuilding
I haven't been able to find an answer to this question. I used Nu
Previously i used the JavaScript API for Facebook Connect, so i had the fb:login-button
We had previously been referring to our Windows Azure libraries via the SDK and
I previously had Passenger 2.2.13 install with NGINX 0.7.65 - I want to install
I previously had a table that is created using hibernate entities. I am using
I have a follow-up question regarding an issue I previously had on SO here
Here is the site in question: http://jayduff.co.uk/ I previously had the images/links on the
I have an application that uses CoreData. I previously had a class named Marker

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.