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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:38:51+00:00 2026-06-15T18:38:51+00:00

i have the following bash script on my server: today=$(date +%Y-%m-%d) find /backups/www -type

  • 0

i have the following bash script on my server:

today=$(date +"%Y-%m-%d")
find /backups/www -type f -mtime -1|xargs tar uf /daily/backup-$today.tar

as you can see it creates backups of files modified/created in the last 24h. However if no files are found, it creates corrupted tar file. I would like to wrap it in if..fi statement so id doesn’t create empty/corrupted tar files.

Can someone help me modify this script?

Thanks

  • 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-15T18:38:52+00:00Added an answer on June 15, 2026 at 6:38 pm

    One relatively simple trick would be this:

    today=$(date +"%Y-%m-%d")
    touch /backups/www/.timestamp
    find /backups/www -type f -mtime -1|xargs tar uf /daily/backup-$today.tar
    

    That way you’re guaranteed to always find at least one file (and it’s minimal in size).

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

Sidebar

Related Questions

I have the following bash script, we can call it script1.sh : #!/bin/bash exec
I have the following bash script: #DIR is something like: /home/foo/foobar/test/ without any whitespace
I have a following bash script: 1 #!/bin/bash 2 query='query= SELECT * WHERE {
I have a shell script file (run.sh) that contains the following: #!/bin/bash %JAVA_HOME%/bin/java -jar
gcc (GCC) 4.7.2 GNU bash, version 4.2.37 Hello, I have the following bash script
I have the following snippet in a bash script written in Solaris 10: printf
Say I have the following file names from an ls in a bash script:
I have this bash script on the server that runs every hour, via cron.
I have the following bash script, that lists the current number of httpd processes,
linux 3.5.6-1.fc17.x86_64 GNU bash, version 4.2.37 Hello, I have the following bash script file.

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.