Find files older than a given file - a few hours
I'm using the following to find all files that are older than a reference file...
find /home/testuser -name "dummyfiles*" ! -newer referencefile.txt
... which works as expected.
However, I want to add a bit of leniency to the time, so that it only finds files that are older than the reference file - a few hours.
For example, if I have a reference file with modification date May 26 11:26
, I want to find files that are older than May 26 9:26
(ie, with a 2-hour leniency on the reference file).
In this example, the following would be correct matches...
May 26 7:00
Apr 15 14:00
... and the following should not match...
Jun 13 9:00
May 26 10:00
Ultimately I want to delete all the files that I find, so would love it if find
was able to handle this requirement? Otherwise, are there any other alternatives that will allow me to delete these files without being too convoluted?
find ksh
bumped to the homepage by Community♦ 1 hour ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I'm using the following to find all files that are older than a reference file...
find /home/testuser -name "dummyfiles*" ! -newer referencefile.txt
... which works as expected.
However, I want to add a bit of leniency to the time, so that it only finds files that are older than the reference file - a few hours.
For example, if I have a reference file with modification date May 26 11:26
, I want to find files that are older than May 26 9:26
(ie, with a 2-hour leniency on the reference file).
In this example, the following would be correct matches...
May 26 7:00
Apr 15 14:00
... and the following should not match...
Jun 13 9:00
May 26 10:00
Ultimately I want to delete all the files that I find, so would love it if find
was able to handle this requirement? Otherwise, are there any other alternatives that will allow me to delete these files without being too convoluted?
find ksh
bumped to the homepage by Community♦ 1 hour ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
Please, can you clarify if you are looking for 1) files older than the reference file 2hour OR more than 2hour (>=) 2) files that are older that the reference file exactly 2 hour. (=)
– lese
Nov 6 '15 at 8:52
I'm looking for files that are older that the reference file less 2 hours. See the example in my question - in the example, I would want all files that are older thanMay 26 9:26
, so it should also match files with datesMay 26 7:00
,Apr 15 14:50
, ... but not match datesJun 13 9:00
orMay 26 10:00
.
– wattostudios
Nov 9 '15 at 2:30
add a comment |
I'm using the following to find all files that are older than a reference file...
find /home/testuser -name "dummyfiles*" ! -newer referencefile.txt
... which works as expected.
However, I want to add a bit of leniency to the time, so that it only finds files that are older than the reference file - a few hours.
For example, if I have a reference file with modification date May 26 11:26
, I want to find files that are older than May 26 9:26
(ie, with a 2-hour leniency on the reference file).
In this example, the following would be correct matches...
May 26 7:00
Apr 15 14:00
... and the following should not match...
Jun 13 9:00
May 26 10:00
Ultimately I want to delete all the files that I find, so would love it if find
was able to handle this requirement? Otherwise, are there any other alternatives that will allow me to delete these files without being too convoluted?
find ksh
I'm using the following to find all files that are older than a reference file...
find /home/testuser -name "dummyfiles*" ! -newer referencefile.txt
... which works as expected.
However, I want to add a bit of leniency to the time, so that it only finds files that are older than the reference file - a few hours.
For example, if I have a reference file with modification date May 26 11:26
, I want to find files that are older than May 26 9:26
(ie, with a 2-hour leniency on the reference file).
In this example, the following would be correct matches...
May 26 7:00
Apr 15 14:00
... and the following should not match...
Jun 13 9:00
May 26 10:00
Ultimately I want to delete all the files that I find, so would love it if find
was able to handle this requirement? Otherwise, are there any other alternatives that will allow me to delete these files without being too convoluted?
find ksh
find ksh
edited Nov 9 '15 at 2:33
wattostudios
asked Oct 29 '15 at 0:19
wattostudioswattostudios
1065
1065
bumped to the homepage by Community♦ 1 hour ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 1 hour ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
Please, can you clarify if you are looking for 1) files older than the reference file 2hour OR more than 2hour (>=) 2) files that are older that the reference file exactly 2 hour. (=)
– lese
Nov 6 '15 at 8:52
I'm looking for files that are older that the reference file less 2 hours. See the example in my question - in the example, I would want all files that are older thanMay 26 9:26
, so it should also match files with datesMay 26 7:00
,Apr 15 14:50
, ... but not match datesJun 13 9:00
orMay 26 10:00
.
– wattostudios
Nov 9 '15 at 2:30
add a comment |
Please, can you clarify if you are looking for 1) files older than the reference file 2hour OR more than 2hour (>=) 2) files that are older that the reference file exactly 2 hour. (=)
– lese
Nov 6 '15 at 8:52
I'm looking for files that are older that the reference file less 2 hours. See the example in my question - in the example, I would want all files that are older thanMay 26 9:26
, so it should also match files with datesMay 26 7:00
,Apr 15 14:50
, ... but not match datesJun 13 9:00
orMay 26 10:00
.
– wattostudios
Nov 9 '15 at 2:30
Please, can you clarify if you are looking for 1) files older than the reference file 2hour OR more than 2hour (>=) 2) files that are older that the reference file exactly 2 hour. (=)
– lese
Nov 6 '15 at 8:52
Please, can you clarify if you are looking for 1) files older than the reference file 2hour OR more than 2hour (>=) 2) files that are older that the reference file exactly 2 hour. (=)
– lese
Nov 6 '15 at 8:52
I'm looking for files that are older that the reference file less 2 hours. See the example in my question - in the example, I would want all files that are older than
May 26 9:26
, so it should also match files with dates May 26 7:00
, Apr 15 14:50
, ... but not match dates Jun 13 9:00
or May 26 10:00
.– wattostudios
Nov 9 '15 at 2:30
I'm looking for files that are older that the reference file less 2 hours. See the example in my question - in the example, I would want all files that are older than
May 26 9:26
, so it should also match files with dates May 26 7:00
, Apr 15 14:50
, ... but not match dates Jun 13 9:00
or May 26 10:00
.– wattostudios
Nov 9 '15 at 2:30
add a comment |
1 Answer
1
active
oldest
votes
Try out with this :
find /home/testuser -name "dummyfiles*" ! -newer referencefile.txt -mmin +120 -print
adding the parameter -mmin +120
find command will return only the files older than 2-hour in comparison to referencefile.txt modification date.
test:
mkdir find
touch find/dummyfiles1 find/dummyfiles2 find/dummyfiles3 find/dummyfiles4 find/referencefile.txt
touch -t 8001031305 dummyfiles1 dummyfiles2
find find/ -name "dummyfiles*" ! -newer find/referencefile.txt -mmin +120
output:
find/dummyfiles1
find/dummyfiles2
1
You should explain why your solution is different to what the OP is already doing, and how it solves their problem.
– cas
Oct 29 '15 at 6:33
Improved the answer, It was so late in my country : )
– lese
Oct 29 '15 at 8:53
No, this doesn't do what you claim. This command matches files that are older thanreferencefile.txt
and at least two hours old. Nothing here says “two hours older than the reference file”.
– Gilles
Oct 31 '15 at 23:00
This answer do exaclty what I claim (don't call me storyteller) : "return only the files older than 2-hour"(it's what I'm claiming). Anyway, maybe I missed understood the question. Waiting for a clarification from the OP
– lese
Nov 6 '15 at 8:54
add a comment |
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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f239374%2ffind-files-older-than-a-given-file-a-few-hours%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try out with this :
find /home/testuser -name "dummyfiles*" ! -newer referencefile.txt -mmin +120 -print
adding the parameter -mmin +120
find command will return only the files older than 2-hour in comparison to referencefile.txt modification date.
test:
mkdir find
touch find/dummyfiles1 find/dummyfiles2 find/dummyfiles3 find/dummyfiles4 find/referencefile.txt
touch -t 8001031305 dummyfiles1 dummyfiles2
find find/ -name "dummyfiles*" ! -newer find/referencefile.txt -mmin +120
output:
find/dummyfiles1
find/dummyfiles2
1
You should explain why your solution is different to what the OP is already doing, and how it solves their problem.
– cas
Oct 29 '15 at 6:33
Improved the answer, It was so late in my country : )
– lese
Oct 29 '15 at 8:53
No, this doesn't do what you claim. This command matches files that are older thanreferencefile.txt
and at least two hours old. Nothing here says “two hours older than the reference file”.
– Gilles
Oct 31 '15 at 23:00
This answer do exaclty what I claim (don't call me storyteller) : "return only the files older than 2-hour"(it's what I'm claiming). Anyway, maybe I missed understood the question. Waiting for a clarification from the OP
– lese
Nov 6 '15 at 8:54
add a comment |
Try out with this :
find /home/testuser -name "dummyfiles*" ! -newer referencefile.txt -mmin +120 -print
adding the parameter -mmin +120
find command will return only the files older than 2-hour in comparison to referencefile.txt modification date.
test:
mkdir find
touch find/dummyfiles1 find/dummyfiles2 find/dummyfiles3 find/dummyfiles4 find/referencefile.txt
touch -t 8001031305 dummyfiles1 dummyfiles2
find find/ -name "dummyfiles*" ! -newer find/referencefile.txt -mmin +120
output:
find/dummyfiles1
find/dummyfiles2
1
You should explain why your solution is different to what the OP is already doing, and how it solves their problem.
– cas
Oct 29 '15 at 6:33
Improved the answer, It was so late in my country : )
– lese
Oct 29 '15 at 8:53
No, this doesn't do what you claim. This command matches files that are older thanreferencefile.txt
and at least two hours old. Nothing here says “two hours older than the reference file”.
– Gilles
Oct 31 '15 at 23:00
This answer do exaclty what I claim (don't call me storyteller) : "return only the files older than 2-hour"(it's what I'm claiming). Anyway, maybe I missed understood the question. Waiting for a clarification from the OP
– lese
Nov 6 '15 at 8:54
add a comment |
Try out with this :
find /home/testuser -name "dummyfiles*" ! -newer referencefile.txt -mmin +120 -print
adding the parameter -mmin +120
find command will return only the files older than 2-hour in comparison to referencefile.txt modification date.
test:
mkdir find
touch find/dummyfiles1 find/dummyfiles2 find/dummyfiles3 find/dummyfiles4 find/referencefile.txt
touch -t 8001031305 dummyfiles1 dummyfiles2
find find/ -name "dummyfiles*" ! -newer find/referencefile.txt -mmin +120
output:
find/dummyfiles1
find/dummyfiles2
Try out with this :
find /home/testuser -name "dummyfiles*" ! -newer referencefile.txt -mmin +120 -print
adding the parameter -mmin +120
find command will return only the files older than 2-hour in comparison to referencefile.txt modification date.
test:
mkdir find
touch find/dummyfiles1 find/dummyfiles2 find/dummyfiles3 find/dummyfiles4 find/referencefile.txt
touch -t 8001031305 dummyfiles1 dummyfiles2
find find/ -name "dummyfiles*" ! -newer find/referencefile.txt -mmin +120
output:
find/dummyfiles1
find/dummyfiles2
edited Oct 29 '15 at 9:04
answered Oct 29 '15 at 2:07
leselese
2,13531327
2,13531327
1
You should explain why your solution is different to what the OP is already doing, and how it solves their problem.
– cas
Oct 29 '15 at 6:33
Improved the answer, It was so late in my country : )
– lese
Oct 29 '15 at 8:53
No, this doesn't do what you claim. This command matches files that are older thanreferencefile.txt
and at least two hours old. Nothing here says “two hours older than the reference file”.
– Gilles
Oct 31 '15 at 23:00
This answer do exaclty what I claim (don't call me storyteller) : "return only the files older than 2-hour"(it's what I'm claiming). Anyway, maybe I missed understood the question. Waiting for a clarification from the OP
– lese
Nov 6 '15 at 8:54
add a comment |
1
You should explain why your solution is different to what the OP is already doing, and how it solves their problem.
– cas
Oct 29 '15 at 6:33
Improved the answer, It was so late in my country : )
– lese
Oct 29 '15 at 8:53
No, this doesn't do what you claim. This command matches files that are older thanreferencefile.txt
and at least two hours old. Nothing here says “two hours older than the reference file”.
– Gilles
Oct 31 '15 at 23:00
This answer do exaclty what I claim (don't call me storyteller) : "return only the files older than 2-hour"(it's what I'm claiming). Anyway, maybe I missed understood the question. Waiting for a clarification from the OP
– lese
Nov 6 '15 at 8:54
1
1
You should explain why your solution is different to what the OP is already doing, and how it solves their problem.
– cas
Oct 29 '15 at 6:33
You should explain why your solution is different to what the OP is already doing, and how it solves their problem.
– cas
Oct 29 '15 at 6:33
Improved the answer, It was so late in my country : )
– lese
Oct 29 '15 at 8:53
Improved the answer, It was so late in my country : )
– lese
Oct 29 '15 at 8:53
No, this doesn't do what you claim. This command matches files that are older than
referencefile.txt
and at least two hours old. Nothing here says “two hours older than the reference file”.– Gilles
Oct 31 '15 at 23:00
No, this doesn't do what you claim. This command matches files that are older than
referencefile.txt
and at least two hours old. Nothing here says “two hours older than the reference file”.– Gilles
Oct 31 '15 at 23:00
This answer do exaclty what I claim (don't call me storyteller) : "return only the files older than 2-hour"(it's what I'm claiming). Anyway, maybe I missed understood the question. Waiting for a clarification from the OP
– lese
Nov 6 '15 at 8:54
This answer do exaclty what I claim (don't call me storyteller) : "return only the files older than 2-hour"(it's what I'm claiming). Anyway, maybe I missed understood the question. Waiting for a clarification from the OP
– lese
Nov 6 '15 at 8:54
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f239374%2ffind-files-older-than-a-given-file-a-few-hours%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please, can you clarify if you are looking for 1) files older than the reference file 2hour OR more than 2hour (>=) 2) files that are older that the reference file exactly 2 hour. (=)
– lese
Nov 6 '15 at 8:52
I'm looking for files that are older that the reference file less 2 hours. See the example in my question - in the example, I would want all files that are older than
May 26 9:26
, so it should also match files with datesMay 26 7:00
,Apr 15 14:50
, ... but not match datesJun 13 9:00
orMay 26 10:00
.– wattostudios
Nov 9 '15 at 2:30