Finding files older than x days on a system with a stripped down busybox

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
9
down vote

favorite
1












I need to find and delete files older than 1 week in the Development unit. There are limited number utilities available on this unit. -mtime find's predicate is not available. How do I check all files which are older than x days in this case?







share|improve this question


















  • 2




    It is unclear what you mean with "mtime is not available". It's not a utility whose name I recognise.
    – Kusalananda
    Aug 21 at 9:35










  • /path/to/my/folder$ find -type f -mtime +7 delete find: unrecognized: -mtime
    – Ravi
    Aug 21 at 9:44










  • share the distro of linux you are using.
    – SivaPrasath
    Aug 21 at 9:47







  • 3




    It looks like it's busybox built without FEATURE_FIND_MTIME. Is FEATURE_FIND_NEWER enabled? Does find -newer work? Does your test utility or the [ builtin of your sh support -nt?
    – Stéphane Chazelas
    Aug 21 at 9:50






  • 1




    You can work around this if you can use those touch -d/date +%s and [ file -nt other-file ]
    – Stéphane Chazelas
    Aug 21 at 10:08














up vote
9
down vote

favorite
1












I need to find and delete files older than 1 week in the Development unit. There are limited number utilities available on this unit. -mtime find's predicate is not available. How do I check all files which are older than x days in this case?







share|improve this question


















  • 2




    It is unclear what you mean with "mtime is not available". It's not a utility whose name I recognise.
    – Kusalananda
    Aug 21 at 9:35










  • /path/to/my/folder$ find -type f -mtime +7 delete find: unrecognized: -mtime
    – Ravi
    Aug 21 at 9:44










  • share the distro of linux you are using.
    – SivaPrasath
    Aug 21 at 9:47







  • 3




    It looks like it's busybox built without FEATURE_FIND_MTIME. Is FEATURE_FIND_NEWER enabled? Does find -newer work? Does your test utility or the [ builtin of your sh support -nt?
    – Stéphane Chazelas
    Aug 21 at 9:50






  • 1




    You can work around this if you can use those touch -d/date +%s and [ file -nt other-file ]
    – Stéphane Chazelas
    Aug 21 at 10:08












up vote
9
down vote

favorite
1









up vote
9
down vote

favorite
1






1





I need to find and delete files older than 1 week in the Development unit. There are limited number utilities available on this unit. -mtime find's predicate is not available. How do I check all files which are older than x days in this case?







share|improve this question














I need to find and delete files older than 1 week in the Development unit. There are limited number utilities available on this unit. -mtime find's predicate is not available. How do I check all files which are older than x days in this case?









share|improve this question













share|improve this question




share|improve this question








edited Aug 21 at 12:05









Stéphane Chazelas

282k53518851




282k53518851










asked Aug 21 at 9:27









Ravi

319213




319213







  • 2




    It is unclear what you mean with "mtime is not available". It's not a utility whose name I recognise.
    – Kusalananda
    Aug 21 at 9:35










  • /path/to/my/folder$ find -type f -mtime +7 delete find: unrecognized: -mtime
    – Ravi
    Aug 21 at 9:44










  • share the distro of linux you are using.
    – SivaPrasath
    Aug 21 at 9:47







  • 3




    It looks like it's busybox built without FEATURE_FIND_MTIME. Is FEATURE_FIND_NEWER enabled? Does find -newer work? Does your test utility or the [ builtin of your sh support -nt?
    – Stéphane Chazelas
    Aug 21 at 9:50






  • 1




    You can work around this if you can use those touch -d/date +%s and [ file -nt other-file ]
    – Stéphane Chazelas
    Aug 21 at 10:08












  • 2




    It is unclear what you mean with "mtime is not available". It's not a utility whose name I recognise.
    – Kusalananda
    Aug 21 at 9:35










  • /path/to/my/folder$ find -type f -mtime +7 delete find: unrecognized: -mtime
    – Ravi
    Aug 21 at 9:44










  • share the distro of linux you are using.
    – SivaPrasath
    Aug 21 at 9:47







  • 3




    It looks like it's busybox built without FEATURE_FIND_MTIME. Is FEATURE_FIND_NEWER enabled? Does find -newer work? Does your test utility or the [ builtin of your sh support -nt?
    – Stéphane Chazelas
    Aug 21 at 9:50






  • 1




    You can work around this if you can use those touch -d/date +%s and [ file -nt other-file ]
    – Stéphane Chazelas
    Aug 21 at 10:08







2




2




It is unclear what you mean with "mtime is not available". It's not a utility whose name I recognise.
– Kusalananda
Aug 21 at 9:35




It is unclear what you mean with "mtime is not available". It's not a utility whose name I recognise.
– Kusalananda
Aug 21 at 9:35












/path/to/my/folder$ find -type f -mtime +7 delete find: unrecognized: -mtime
– Ravi
Aug 21 at 9:44




/path/to/my/folder$ find -type f -mtime +7 delete find: unrecognized: -mtime
– Ravi
Aug 21 at 9:44












share the distro of linux you are using.
– SivaPrasath
Aug 21 at 9:47





share the distro of linux you are using.
– SivaPrasath
Aug 21 at 9:47





3




3




It looks like it's busybox built without FEATURE_FIND_MTIME. Is FEATURE_FIND_NEWER enabled? Does find -newer work? Does your test utility or the [ builtin of your sh support -nt?
– Stéphane Chazelas
Aug 21 at 9:50




It looks like it's busybox built without FEATURE_FIND_MTIME. Is FEATURE_FIND_NEWER enabled? Does find -newer work? Does your test utility or the [ builtin of your sh support -nt?
– Stéphane Chazelas
Aug 21 at 9:50




1




1




You can work around this if you can use those touch -d/date +%s and [ file -nt other-file ]
– Stéphane Chazelas
Aug 21 at 10:08




You can work around this if you can use those touch -d/date +%s and [ file -nt other-file ]
– Stéphane Chazelas
Aug 21 at 10:08










2 Answers
2






active

oldest

votes

















up vote
10
down vote



accepted










-mtime is a standard predicate of find (contrary to -delete) but it looks like you have a stripped down version of busybox, where the FEATURE_FIND_MTIME feature has been disabled at build time.



If you can rebuild busybox with it enabled, you should be able to do:



find . -mtime +6 -type f -exec rm -f +


Or if FEATURE_FIND_DELETE is also enabled:



find . -mtime +6 -type f -delete


If not, other options could be to use find -newer (assuming FEATURE_FIND_NEWER is enabled) on a file that is set to have a one week old modification time.



touch -d "@$(($(date +%s) - 7 * 86400))" ../ref &&
find . ! -type f -newer ../ref -exec rm -f +


Or if -newer is not available but sh's [ supports -nt:



touch -d "@$(($(date +%s) - 7 * 86400))" ../ref &&
find . ! -type f -exec sh -c '
for f do
[ "$f" -nt ../ref ] || printf "%s" "$f"
done' sh + |
xargs -0 rm -f





share|improve this answer






















  • Yes, busybox was a lighter version here. After re-build, find . -mtime +6 -type f -exec rm ; worked for me
    – Ravi
    Aug 21 at 11:42

















up vote
2
down vote













From man find:




-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.



-ctime n



File's status was last changed n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file status change times.




Depending on the use cases of the files you want to delete, these are your only other options for find. Why is mtime not available? What filesystem are you using? Did you explore any other options?






share|improve this answer




















  • Asking more questions of the OP should be done as clarifying comments, not answers.
    – Jeff Schaller
    Aug 21 at 11:59










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f463813%2ffinding-files-older-than-x-days-on-a-system-with-a-stripped-down-busybox%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
10
down vote



accepted










-mtime is a standard predicate of find (contrary to -delete) but it looks like you have a stripped down version of busybox, where the FEATURE_FIND_MTIME feature has been disabled at build time.



If you can rebuild busybox with it enabled, you should be able to do:



find . -mtime +6 -type f -exec rm -f +


Or if FEATURE_FIND_DELETE is also enabled:



find . -mtime +6 -type f -delete


If not, other options could be to use find -newer (assuming FEATURE_FIND_NEWER is enabled) on a file that is set to have a one week old modification time.



touch -d "@$(($(date +%s) - 7 * 86400))" ../ref &&
find . ! -type f -newer ../ref -exec rm -f +


Or if -newer is not available but sh's [ supports -nt:



touch -d "@$(($(date +%s) - 7 * 86400))" ../ref &&
find . ! -type f -exec sh -c '
for f do
[ "$f" -nt ../ref ] || printf "%s" "$f"
done' sh + |
xargs -0 rm -f





share|improve this answer






















  • Yes, busybox was a lighter version here. After re-build, find . -mtime +6 -type f -exec rm ; worked for me
    – Ravi
    Aug 21 at 11:42














up vote
10
down vote



accepted










-mtime is a standard predicate of find (contrary to -delete) but it looks like you have a stripped down version of busybox, where the FEATURE_FIND_MTIME feature has been disabled at build time.



If you can rebuild busybox with it enabled, you should be able to do:



find . -mtime +6 -type f -exec rm -f +


Or if FEATURE_FIND_DELETE is also enabled:



find . -mtime +6 -type f -delete


If not, other options could be to use find -newer (assuming FEATURE_FIND_NEWER is enabled) on a file that is set to have a one week old modification time.



touch -d "@$(($(date +%s) - 7 * 86400))" ../ref &&
find . ! -type f -newer ../ref -exec rm -f +


Or if -newer is not available but sh's [ supports -nt:



touch -d "@$(($(date +%s) - 7 * 86400))" ../ref &&
find . ! -type f -exec sh -c '
for f do
[ "$f" -nt ../ref ] || printf "%s" "$f"
done' sh + |
xargs -0 rm -f





share|improve this answer






















  • Yes, busybox was a lighter version here. After re-build, find . -mtime +6 -type f -exec rm ; worked for me
    – Ravi
    Aug 21 at 11:42












up vote
10
down vote



accepted







up vote
10
down vote



accepted






-mtime is a standard predicate of find (contrary to -delete) but it looks like you have a stripped down version of busybox, where the FEATURE_FIND_MTIME feature has been disabled at build time.



If you can rebuild busybox with it enabled, you should be able to do:



find . -mtime +6 -type f -exec rm -f +


Or if FEATURE_FIND_DELETE is also enabled:



find . -mtime +6 -type f -delete


If not, other options could be to use find -newer (assuming FEATURE_FIND_NEWER is enabled) on a file that is set to have a one week old modification time.



touch -d "@$(($(date +%s) - 7 * 86400))" ../ref &&
find . ! -type f -newer ../ref -exec rm -f +


Or if -newer is not available but sh's [ supports -nt:



touch -d "@$(($(date +%s) - 7 * 86400))" ../ref &&
find . ! -type f -exec sh -c '
for f do
[ "$f" -nt ../ref ] || printf "%s" "$f"
done' sh + |
xargs -0 rm -f





share|improve this answer














-mtime is a standard predicate of find (contrary to -delete) but it looks like you have a stripped down version of busybox, where the FEATURE_FIND_MTIME feature has been disabled at build time.



If you can rebuild busybox with it enabled, you should be able to do:



find . -mtime +6 -type f -exec rm -f +


Or if FEATURE_FIND_DELETE is also enabled:



find . -mtime +6 -type f -delete


If not, other options could be to use find -newer (assuming FEATURE_FIND_NEWER is enabled) on a file that is set to have a one week old modification time.



touch -d "@$(($(date +%s) - 7 * 86400))" ../ref &&
find . ! -type f -newer ../ref -exec rm -f +


Or if -newer is not available but sh's [ supports -nt:



touch -d "@$(($(date +%s) - 7 * 86400))" ../ref &&
find . ! -type f -exec sh -c '
for f do
[ "$f" -nt ../ref ] || printf "%s" "$f"
done' sh + |
xargs -0 rm -f






share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 21 at 16:50

























answered Aug 21 at 11:38









Stéphane Chazelas

282k53518851




282k53518851











  • Yes, busybox was a lighter version here. After re-build, find . -mtime +6 -type f -exec rm ; worked for me
    – Ravi
    Aug 21 at 11:42
















  • Yes, busybox was a lighter version here. After re-build, find . -mtime +6 -type f -exec rm ; worked for me
    – Ravi
    Aug 21 at 11:42















Yes, busybox was a lighter version here. After re-build, find . -mtime +6 -type f -exec rm ; worked for me
– Ravi
Aug 21 at 11:42




Yes, busybox was a lighter version here. After re-build, find . -mtime +6 -type f -exec rm ; worked for me
– Ravi
Aug 21 at 11:42












up vote
2
down vote













From man find:




-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.



-ctime n



File's status was last changed n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file status change times.




Depending on the use cases of the files you want to delete, these are your only other options for find. Why is mtime not available? What filesystem are you using? Did you explore any other options?






share|improve this answer




















  • Asking more questions of the OP should be done as clarifying comments, not answers.
    – Jeff Schaller
    Aug 21 at 11:59














up vote
2
down vote













From man find:




-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.



-ctime n



File's status was last changed n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file status change times.




Depending on the use cases of the files you want to delete, these are your only other options for find. Why is mtime not available? What filesystem are you using? Did you explore any other options?






share|improve this answer




















  • Asking more questions of the OP should be done as clarifying comments, not answers.
    – Jeff Schaller
    Aug 21 at 11:59












up vote
2
down vote










up vote
2
down vote









From man find:




-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.



-ctime n



File's status was last changed n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file status change times.




Depending on the use cases of the files you want to delete, these are your only other options for find. Why is mtime not available? What filesystem are you using? Did you explore any other options?






share|improve this answer












From man find:




-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.



-ctime n



File's status was last changed n*24 hours ago. See the comments for -atime to understand how rounding affects the interpretation of file status change times.




Depending on the use cases of the files you want to delete, these are your only other options for find. Why is mtime not available? What filesystem are you using? Did you explore any other options?







share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 21 at 9:35









OneK

1013




1013











  • Asking more questions of the OP should be done as clarifying comments, not answers.
    – Jeff Schaller
    Aug 21 at 11:59
















  • Asking more questions of the OP should be done as clarifying comments, not answers.
    – Jeff Schaller
    Aug 21 at 11:59















Asking more questions of the OP should be done as clarifying comments, not answers.
– Jeff Schaller
Aug 21 at 11:59




Asking more questions of the OP should be done as clarifying comments, not answers.
– Jeff Schaller
Aug 21 at 11:59












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f463813%2ffinding-files-older-than-x-days-on-a-system-with-a-stripped-down-busybox%23new-answer', 'question_page');

);

Post as a guest













































































這個網誌中的熱門文章

How to combine Bézier curves to a surface?

Mutual Information Always Non-negative

Why am i infinitely getting the same tweet with the Twitter Search API?