LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   script to remove files older than // modification time (https://www.linuxquestions.org/questions/linux-server-73/script-to-remove-files-older-than-modification-time-4175636349/)

overlord73 08-14-2018 09:16 AM

script to remove files older than // modification time
 
Hi,

a public share (samba, OpenMediaVault) is used for temporary file sharing.
My intention is to keep this share clearly arranged and remove all files older than 30 days.
Therefore daily script is running:

Code:

find '/mountpoint/' -mtime +29 -type f -delete
For newly created files it is okay, but the problem is, that if a file was copied from another host to this share, the modification date doesn't change. The file keeps the old date and during the next scheduled run the script deletes this file.

Any ideas how I can fix this issue? Is there an option that samba always sets a new modtime while copying or does another solution exists?

thx

lougavulin 08-14-2018 10:10 AM

Well, how do you do the files copies on your temporary file sharing ?

rknichols 08-14-2018 12:59 PM

You can use "ctime" rather than "mtime". That will tell the last time anything in the inode changed (other than the automatic "atime" update due to the file being read).

Having a copied file retain the mtime of the original is standard DOS/Windows behavior.

overlord73 08-15-2018 12:14 AM

hm ok, thx!
Indeed ctime seems to do the job. Usually the copy process is from Windows-Hosts.


All times are GMT -5. The time now is 07:52 PM.