Unable to retrieve all files older than three days with the "find" command in Linux

Hi there,

We have a Linux script that creates a backup .zip file nightly. Once the .zip file is created, I run another bash script to copy it to a mount directory, which is connected to an Azure VM.  That part is working just fine, but I need to only keep three days worth of backup in the Azure mount directory.  I'm running the "find" command below, but it doesn't seem to find the right files that should be deleted.  

find /data/oracle/devpdb/dpdump/ -name "oneg_*.zip" -mtime +3

It's not returning anything, but I know I have some .zip files which start with "oneg_" that are over three days old.  If I run the command below, it find the right files, but it doesn't have the check for files that are three days or older.

find /data/oracle/devpdb/dpdump/ -name "oneg_*.zip"

What am I doing wrong?
Christian PalaciosSenior IT Systems AdministratorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
try -daystart -mtime 3

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Are you certain that the last modified time is the correct parameter to search for?  Maybe you need to look at the creation time (ctime) instead?
Gerwin Jansen, EE MVETopic Advisor Commented:
You can add a line to your Linux script that creates a 'timestamped' file that you then use with your find command, like this:
touch --date="$(date -d '3 days ago')" somefile

Open in new window

Modify your find command to find newer files:
find /data/oracle/devpdb/dpdump/ -name "oneg_*.zip" -newer somefile

Open in new window

or if you want to find older files:
find /data/oracle/devpdb/dpdump/ -name "oneg_*.zip" ! -newer somefile

Open in new window

Note: don't give somefile a .zip extension because then the last find command will then find your somefile.zip file as well.
Christian PalaciosSenior IT Systems AdministratorAuthor Commented:
Thank you David.  That did the trick!  I was able to only the files that were older than 3 days after testing that it actually found the right files.
Christian PalaciosSenior IT Systems AdministratorAuthor Commented:
Worked well!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.