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

  • Home
  • SEARCH
  • 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 8835211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:12:30+00:00 2026-06-14T09:12:30+00:00

I’m creating backup of my database every day. For hard disk saving how can

  • 0

I’m creating backup of my database every day.

For hard disk saving how can I delete files older than 2 weeks AND (day of month) % 14 != 0 from shell script?

So I’m looking for command like find / -mtime +14 -exec rm {} \;, with addition of not deleteting files created in 14’th or 28’th day of any month.

I’d like to have daily backups for last 2 weeks and once every 2 weeks(almost) afterwards?

PHP code in loop would be:

$mtime = filemtime($file); // Last modified date of file (created)
$day_mtime = date('j', $mtime); // Day of month (1-31)
$two_weeks_ago = time() - 60 * 60 * 24 * 14;

if ($mtime < $two_weeks_ago && $day_mtime % 14 != 0) {
    // Delete file older than 2 weeks 
    // AND not modified not 14'th nor 28'th day of month
}
  • 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-14T09:12:31+00:00Added an answer on June 14, 2026 at 9:12 am

    This is the bash equivalent. A couple of point to note when moving from php to bash:

    • In bash $ means “the value of…” so mtime is the variable and $mtime is the value of the variable
    • The notation $(...) means run the command in the parenthesis and capture with its output
      So, $(stat -c %Y $file) is replaced with the output of stat -c %Y $file
    • There can be no spaces around the assignment operators a=b works, a = b does not

      mtime=$(stat -c %Y $file)
      day_mtime=$(date -d@$mtime +%d)
      two_weeks_ago=$(date -d '2 weeks ago' +%s)
      mod_14_day=$(expr $day_mtime 14)
      if [ $mtime -lt $two_weeks_ago ] && [ $mod_14_day -eq 0 ] ; then
      fi
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have thousands of HTML files to process using Groovy/Java and I need to
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

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.