Christian Palacios
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?
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
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
What am I doing wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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:
Modify your find command to find newer files:
or if you want to find older files:
Note: don't give somefile a .zip extension because then the last find command will then find your somefile.zip file as well.
touch --date="$(date -d '3 days ago')" somefile
Modify your find command to find newer files:
find /data/oracle/devpdb/dpdump/ -name "oneg_*.zip" -newer somefile
or if you want to find older files:
find /data/oracle/devpdb/dpdump/ -name "oneg_*.zip" ! -newer somefile
Note: don't give somefile a .zip extension because then the last find command will then find your somefile.zip file as well.
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.
ASKER
Worked well!