Link to home
Start Free TrialLog in
Avatar of Christian Palacios
Christian PalaciosFlag for Canada

asked on

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?
ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start 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?
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.
Avatar of Christian Palacios

ASKER

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.
Worked well!