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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:00:43+00:00 2026-05-10T16:00:43+00:00

Cron installation is vixie-cron /etc/cron.daily/rmspam.cron #!/bin/bash /usr/bin/rm /home/user/Maildir/.SPAM/cur/*; I Have this simple bash script

  • 0

Cron installation is vixie-cron

/etc/cron.daily/rmspam.cron

#!/bin/bash /usr/bin/rm /home/user/Maildir/.SPAM/cur/*; 

I Have this simple bash script that I want to add to a cron job (also includes spam learning commands before) but this part always fails with ‘File or directory not found’ From what I figure is the metachar isn’t being interperted correctly when run as a cron job. If I execute the script from the commandline it works fine.

I’d like a why for this not working and of course a working solution 🙂

Thanks

edit #1 came back to this question when I got popular question badge for it. I first did this,

#!/bin/bash find  /home/user/Maildir/.SPAM/cur/ -t file | xargs rm 

and just recently was reading through the xargs man page and changed it to this

#!/bin/bash find  /home/user/Maildir/.SPAM/cur/ -t file | xargs --no-run-if-empty rm 

short xargs option is -r

  • 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. 2026-05-10T16:00:44+00:00Added an answer on May 10, 2026 at 4:00 pm

    If there are no files in the directory, then the wildcard will not be expanded and will be passed to the command directly. There is no file called ‘*’, and then the command fails with ‘File or directory not found.’ Try this instead:

    if [ -f /home/user/Maildir/.SPAM/cur/* ]; then     rm /home/user/Maildir/.SPAM/cur/* fi 

    Or just use the ‘-f’ flag to rm. The other problem with this command is what happens when there is too much spam for the maximum length of the command line. Something like this is probably better overall:

    find /home/user/Maildir/.SPAM/cur -type f -exec rm '{}' + 

    If you have an old find that only execs rm one file at a time:

    find /home/user/Maildir/.SPAM/cur -type f | xargs rm 

    That handles too many files as well as no files. Thanks to Charles Duffy for pointing out the + option to -exec in find.

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

Sidebar

Related Questions

My cron : 45 10 * * * source /home/ThinkCode/Test/hello.sh hello.sh : #!/bin/bash echo
I have a cron job scrape.sh that look like this: #!/bin/bash touch rage cd
I have a daily cron job that email PDFs to customers. I want to
Cron example: */1 * * * * /usr/bin/php /html/includes/CRON.php > /html/includes/logs/CRON_LOG.txt This is how
I have a cron job set like php /home/novinarb/public_html/index.php --uri=cron/24satahr but the 'uri' param
I wrote the following shell script: #!/bin/bash MAIL=/usr/mail/${LOGNAME:?} . /installations/etl_scripts/etl_job.properties JOB_LOG_FILE_PATH=$JOB_LOG_FILE_PATH export JOB_LOG_FILE_PATH JOB_LOG_FILE_NAME=$JOB_LOG_FILE_NAME
I have a cron task that runs once a day, using Heroku's Daily Cron
I have a daily cron task which automatically unrars a rar file and processes
I have created the cron job with whenever (https://github.com/javan/whenever): every 1.hours do rake scrape
If I have a cron job that run every 10 minutes and for some

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.