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?
 
David Johnson, CD, MVPOwnerCommented:
try -daystart -mtime 3
0
 
serialbandCommented:
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?
0
 
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.
0
 
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.
0
 
Christian PalaciosSenior IT Systems AdministratorAuthor Commented:
Worked well!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.