What's new

How to remove one day old file....

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

octopus

Part of the Furniture
I have tried to remove file as is age of 1 day or more old.

Tried this: find /jffs/scripts/file_to_remove -name "file_to_remove" -mtime +1 -exec rm -f '{}' \;

but -mtime +1 doesn't recognise and don't remove mention file. Is -mtime a valid command in 384.15_alpha1?
Code:
Modification time (-mtime): The timestamp when the file was last modified
mtime is greater than (+N), less than (-N),".
I have run out of suggestions now, anyone who knows how to make this work or have any other proposal.

Octopus :rolleyes:
 
It works on 384.14_2 with either built-in find or entware find for me. Do you really need to include the filename in the search path?
Code:
rtradmin@RT-AC68U-8C78:/jffs/scripts# /usr/bin/find /jffs/scripts/stubby.postconf -name "stubby.postconf" -mtime +1 -exec ls -l {} +
-rwxr-xr-x    1 rtradmin root           562 Dec  2 19:36 /jffs/scripts/stubby.postconf
rtradmin@RT-AC68U-8C78:/jffs/scripts# /opt/bin/find /jffs/scripts/stubby.postconf -name "stubby.postconf" -mtime +1 -exec ls -l {} +
-rwxr-xr-x    1 rtradmin root           562 Dec  2 19:36 /jffs/scripts/stubby.postconf
 
It works on 384.14_2 with either built-in find or entware find for me. Do you really need to include the filename in the search path?
Seems I don't need filename in search part, found an examlpe and just copy that for testing
 
I can't still get it working, my file is "abc.file" and time stamp: 2020-01-22 15:47 and it's more than 1day old.
tested both: "-mtime +1 -exec ls -l {} +" and " -mtime +1 -exec rm -f '{}' \;"
 
Maybe it's not long enough to meet one day. Try the "-mmin +1300" instead (minutes vs days).
 
Maybe it's not long enough to meet one day. Try the "-mmin +1300" instead (minutes vs days).
Then I get: find: unrecognized: -mmin
 
If -mtime +1 doesn't work, I assume if you changed it to -mtime -1 it would work, at least for another hour or so until it reaches 1 full day? I'm guessing it's a timezone issue with the file stamp and the current time the find util pulls.
 
This is a classic find gotcha.

-mtime n
File's data was last modified n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file modification times.
-atime n
File was last accessed n*24 hours ago. When find figures out how many 24-hour periods ago the file was last accessed, any fractional part is ignored, so to match -atime +1, a file has to have been accessed at least two days ago.
 
So 3 different buckets of time:
1. Less than 1 day
2. Between 1 day and 2 days
3. More than 2 days
Code:
rtradmin@RT-AC68U-8C78:/jffs/scripts# /usr/bin/find /jffs/scripts -mtime -1 -exec ls -ld {} +
drwxr-xr-x    2 rtradmin root             0 Jan 23 09:27 /jffs/scripts
-rwxr-xr-x    1 rtradmin root         16645 Jan 23 09:27 /jffs/scripts/nsrum
-rwxr-xr-x    1 rtradmin root         99252 Jan 22 14:41 /jffs/scripts/unbound_manager.sh
-rwxr-xr-x    1 rtradmin root            97 Jan 23 10:38 /jffs/scripts/services-start
-rwxr-xr-x    1 rtradmin root           430 Jan 22 14:14 /jffs/scripts/unmount
-rwxr-xr-x    1 rtradmin root          1080 Jan 22 17:12 /jffs/scripts/dnsmasq.postconf
-rw-rw-rw-    1 rtradmin root            37 Jan 22 14:41 /jffs/scripts/unbound_manager.md5
-rwxr-xr-x    1 rtradmin root          3262 Jan 23 09:02 /jffs/scripts/update-notification

rtradmin@RT-AC68U-8C78:/jffs/scripts# /usr/bin/find /jffs/scripts -mtime 1 -exec ls -ld {} +
-rwxr-xr-x    1 rtradmin root        111973 Jan 22 11:44 /jffs/scripts/amtm
-rwxr-xr-x    1 rtradmin root           139 Jan 22 14:07 /jffs/scripts/service-event
-rwxr-xr-x    1 rtradmin root        214268 Jan 22 12:17 /jffs/scripts/firewall
-rwxr-xr-x    1 rtradmin root           325 Jan 22 13:58 /jffs/scripts/post-mount
-rwxr-xr-x    1 rtradmin root           101 Jan 22 12:17 /jffs/scripts/firewall-start
-rwxr-xr-x    1 rtradmin root           121 Jan 22 13:43 /jffs/scripts/services-stop
-rwxr-xr-x    1 rtradmin root           670 Jan 22 12:33 /jffs/scripts/post-mount.div

rtradmin@RT-AC68U-8C78:/jffs/scripts# /usr/bin/find /jffs/scripts -mtime +1 -exec ls -ld {} +
-rwxr-xr-x    1 rtradmin root           345 Jan 11 23:23 /jffs/scripts/adblock_unbound.sh
-rwxr-xr-x    1 rtradmin root           562 Dec  2 19:36 /jffs/scripts/stubby.postconf
-rwxrwxrwx    1 rtradmin root           957 Jan  7 14:50 /jffs/scripts/hosts2unbound.sh
-rwxr-xr-x    1 rtradmin root          1867 Jan 15 08:05 /jffs/scripts/unbound-check.sh
-rw-r--r--    1 rtradmin root           631 Jan  9 19:38 /jffs/scripts/unbchk.sh.orig
-rw-rw----    1 rtradmin root           990 Dec  3 06:22 /jffs/scripts/httpd_check.sh
-rwxr-xr-x    1 rtradmin root           769 Jan  1 23:25 /jffs/scripts/routerbackup.sh
-rwx--x---    1 rtradmin root          5864 Dec 10 08:01 /jffs/scripts/tls-alert.sh
 
So 3 different buckets of time:
1. Less than 1 day
2. Between 1 day and 2 days
3. More than 2 days

Thank you.
Now I see, +1 is more than 2 days, thats why it's not working.
 

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top