How can I get files using find command2019 Community Moderator ElectionWhy is looping over find's output bad practice?Why does find -mtime +1 only return files older than 2 days?Understanding the -exec option of `find`How to have find only search for files in changed directories?Find command returns wrong filesFind files older than x amount of time in specific directory with ignoring subdirectoriesdelete folders older than 1 dayPrint the files that find acts onFind files in globbed directories excluding some subpathsHow to find files with specific extensions, while excluding some names in the current directory only?find and delete files older than specific days and have specific string in filenamesRemoving names of pruned directories from output of find command“ls” (or other) command to get the *complete* date time on AIX 7.1
Why is so much work done on numerical verification of the Riemann Hypothesis?
Why is it that I can sometimes guess the next note?
What does Apple's new App Store requirement mean
How to align my equation to left?
Review your own paper in Mathematics
How to make money from a browser who sees 5 seconds into the future of any web page?
Making grids in QGIS
How can ping know if my host is down
Is this part of the description of the Archfey warlock's Misty Escape feature redundant?
How to create a paid keyvalue store
Is there a nicer/politer/more positive alternative for "negates"?
Why does the Sun have different day lengths, but not the gas giants?
How to explain what's wrong with this application of the chain rule?
Birthday Problem Paraphrased
What is going on with gets(stdin) on the site coderbyte?
risk of flooding in petra in november
Has any country ever had 2 former presidents in jail simultaneously?
Is it allowed to activate the ability of multiple planeswalkers in a single turn?
Why do Radio Buttons not fill the entire outer circle?
Why does Java 12 try to convert the result of a switch to a number?
Why Shazam when there is already Superman?
What is the duration of the spell Creation when used to create non-precious metals?
It grows, but water kills it
Does "he squandered his car on drink" sound natural?
How can I get files using find command
2019 Community Moderator ElectionWhy is looping over find's output bad practice?Why does find -mtime +1 only return files older than 2 days?Understanding the -exec option of `find`How to have find only search for files in changed directories?Find command returns wrong filesFind files older than x amount of time in specific directory with ignoring subdirectoriesdelete folders older than 1 dayPrint the files that find acts onFind files in globbed directories excluding some subpathsHow to find files with specific extensions, while excluding some names in the current directory only?find and delete files older than specific days and have specific string in filenamesRemoving names of pruned directories from output of find command“ls” (or other) command to get the *complete* date time on AIX 7.1
How to use find command to get only files from the current directory (excluding subdirectories and its files) older than a day on AIX?
find aix
add a comment |
How to use find command to get only files from the current directory (excluding subdirectories and its files) older than a day on AIX?
find aix
4
Please always mention your operating system! You already wasted your time on Ask Ubuntu because you didn't tell us you were using AIX and now you have reposted here (which is fine, AIX is welcome here) and you still didn't tell us you're using AIX! I had to edit it in. The basic tools likefind
vary considerably between the different implementations, so you always need to tell us what OS you are using. The shell you are using, ksh in your case, is irrelevant.
– terdon♦
Mar 18 at 13:13
Similar: delete folders older than 1 day
– Stéphane Chazelas
Mar 19 at 7:53
add a comment |
How to use find command to get only files from the current directory (excluding subdirectories and its files) older than a day on AIX?
find aix
How to use find command to get only files from the current directory (excluding subdirectories and its files) older than a day on AIX?
find aix
find aix
edited Mar 18 at 13:10
terdon♦
132k32262441
132k32262441
asked Mar 18 at 10:58
AnonyAnony
1192
1192
4
Please always mention your operating system! You already wasted your time on Ask Ubuntu because you didn't tell us you were using AIX and now you have reposted here (which is fine, AIX is welcome here) and you still didn't tell us you're using AIX! I had to edit it in. The basic tools likefind
vary considerably between the different implementations, so you always need to tell us what OS you are using. The shell you are using, ksh in your case, is irrelevant.
– terdon♦
Mar 18 at 13:13
Similar: delete folders older than 1 day
– Stéphane Chazelas
Mar 19 at 7:53
add a comment |
4
Please always mention your operating system! You already wasted your time on Ask Ubuntu because you didn't tell us you were using AIX and now you have reposted here (which is fine, AIX is welcome here) and you still didn't tell us you're using AIX! I had to edit it in. The basic tools likefind
vary considerably between the different implementations, so you always need to tell us what OS you are using. The shell you are using, ksh in your case, is irrelevant.
– terdon♦
Mar 18 at 13:13
Similar: delete folders older than 1 day
– Stéphane Chazelas
Mar 19 at 7:53
4
4
Please always mention your operating system! You already wasted your time on Ask Ubuntu because you didn't tell us you were using AIX and now you have reposted here (which is fine, AIX is welcome here) and you still didn't tell us you're using AIX! I had to edit it in. The basic tools like
find
vary considerably between the different implementations, so you always need to tell us what OS you are using. The shell you are using, ksh in your case, is irrelevant.– terdon♦
Mar 18 at 13:13
Please always mention your operating system! You already wasted your time on Ask Ubuntu because you didn't tell us you were using AIX and now you have reposted here (which is fine, AIX is welcome here) and you still didn't tell us you're using AIX! I had to edit it in. The basic tools like
find
vary considerably between the different implementations, so you always need to tell us what OS you are using. The shell you are using, ksh in your case, is irrelevant.– terdon♦
Mar 18 at 13:13
Similar: delete folders older than 1 day
– Stéphane Chazelas
Mar 19 at 7:53
Similar: delete folders older than 1 day
– Stéphane Chazelas
Mar 19 at 7:53
add a comment |
1 Answer
1
active
oldest
votes
Assuming that the implementation of find
on your Unix has the -maxdepth
predicate (it's non-standard, but often available), the following find
command would do that:
find . -maxdepth 1 -type f -mtime +0
This would print the names of the regular files (i.e. not directories, sockets, named pipes etc.) whose modification timestamp was more than 24 hours ago to the terminal.
If -maxdepth
can't be used, then consider
find . ! -name . -prune -type f -mtime +0 -print
This means:
- If the current thing
find
is looking at is not.
(! -name .
), the current directory, then
Prune that path from the search path offind
(-prune
). This stopsfind
from even considering entering any subdirectories.- If the thing is a regular file (
-type f
), and - If its modification timestamp is older than 24 hours (
-mtime +0
), then - Print the name of the thing we've found (
-print
).
Regarding -mtime +0
: On your AIX system, see the note regarding the semantics of -mtime
to determine whether to use -mtime +0
or -mtime +1
. If you want the UNIX03 behaviour, you should be using -mtime +0
to find files with a modification timestamp of more than 24 hours ago (and set the environment variables XPG_SUS_ENV
to ON
and XPG_UNIX98
to OFF
, in accordance with that note in the manual).
By default, find
outputs the pathnames of the found files. This means that you'll get filenames prepended by ./
from the above command. If you don't want that, then you will have to call the basename
utility for each found filename.
You can do that like this:
find . ! -name . -prune -type f -mtime +0 -exec basename ;
In comments you mention that you'd like to compress these files. For this, there is no need to call the basename
utility. Just call gzip
(or whatever compression utility you'd like to use) instead:
find . ! -name . -prune -type f -mtime +0 -exec gzip +
Depending on whether you'd like to do something further with these files, you may look for similar question on this site, e.g. Why is looping over find's output bad practice?
Also related:
- Understanding the -exec option of `find`
2
Comments are not for extended discussion; this conversation has been moved to chat.
– terdon♦
Mar 18 at 13:14
Is there any way using xargs to implement the same?
– Anony
Mar 18 at 13:37
@Anony Not in any way that would help I think. Also, this comment section was archived in a chat. Do consider using it. Also note that I've asked multiple times for the actual command that you are using. I can't debug anything without seeing it. Do not post further comments in this thread, but do feel welcome to use the chat.
– Kusalananda
Mar 18 at 13:41
1
Shouldn’t it be-mtime +0
? See Why does find -mtime +1 only return files older than 2 days?
– Melebius
Mar 19 at 7:29
@StéphaneChazelas Sorted. Though, thefind
on OpenBSD seems to have different semantics for-mtime
and you would have to use+1
there rather than+0
.
– Kusalananda
Mar 19 at 10:35
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%2f506959%2fhow-can-i-get-files-using-find-command%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
Assuming that the implementation of find
on your Unix has the -maxdepth
predicate (it's non-standard, but often available), the following find
command would do that:
find . -maxdepth 1 -type f -mtime +0
This would print the names of the regular files (i.e. not directories, sockets, named pipes etc.) whose modification timestamp was more than 24 hours ago to the terminal.
If -maxdepth
can't be used, then consider
find . ! -name . -prune -type f -mtime +0 -print
This means:
- If the current thing
find
is looking at is not.
(! -name .
), the current directory, then
Prune that path from the search path offind
(-prune
). This stopsfind
from even considering entering any subdirectories.- If the thing is a regular file (
-type f
), and - If its modification timestamp is older than 24 hours (
-mtime +0
), then - Print the name of the thing we've found (
-print
).
Regarding -mtime +0
: On your AIX system, see the note regarding the semantics of -mtime
to determine whether to use -mtime +0
or -mtime +1
. If you want the UNIX03 behaviour, you should be using -mtime +0
to find files with a modification timestamp of more than 24 hours ago (and set the environment variables XPG_SUS_ENV
to ON
and XPG_UNIX98
to OFF
, in accordance with that note in the manual).
By default, find
outputs the pathnames of the found files. This means that you'll get filenames prepended by ./
from the above command. If you don't want that, then you will have to call the basename
utility for each found filename.
You can do that like this:
find . ! -name . -prune -type f -mtime +0 -exec basename ;
In comments you mention that you'd like to compress these files. For this, there is no need to call the basename
utility. Just call gzip
(or whatever compression utility you'd like to use) instead:
find . ! -name . -prune -type f -mtime +0 -exec gzip +
Depending on whether you'd like to do something further with these files, you may look for similar question on this site, e.g. Why is looping over find's output bad practice?
Also related:
- Understanding the -exec option of `find`
2
Comments are not for extended discussion; this conversation has been moved to chat.
– terdon♦
Mar 18 at 13:14
Is there any way using xargs to implement the same?
– Anony
Mar 18 at 13:37
@Anony Not in any way that would help I think. Also, this comment section was archived in a chat. Do consider using it. Also note that I've asked multiple times for the actual command that you are using. I can't debug anything without seeing it. Do not post further comments in this thread, but do feel welcome to use the chat.
– Kusalananda
Mar 18 at 13:41
1
Shouldn’t it be-mtime +0
? See Why does find -mtime +1 only return files older than 2 days?
– Melebius
Mar 19 at 7:29
@StéphaneChazelas Sorted. Though, thefind
on OpenBSD seems to have different semantics for-mtime
and you would have to use+1
there rather than+0
.
– Kusalananda
Mar 19 at 10:35
add a comment |
Assuming that the implementation of find
on your Unix has the -maxdepth
predicate (it's non-standard, but often available), the following find
command would do that:
find . -maxdepth 1 -type f -mtime +0
This would print the names of the regular files (i.e. not directories, sockets, named pipes etc.) whose modification timestamp was more than 24 hours ago to the terminal.
If -maxdepth
can't be used, then consider
find . ! -name . -prune -type f -mtime +0 -print
This means:
- If the current thing
find
is looking at is not.
(! -name .
), the current directory, then
Prune that path from the search path offind
(-prune
). This stopsfind
from even considering entering any subdirectories.- If the thing is a regular file (
-type f
), and - If its modification timestamp is older than 24 hours (
-mtime +0
), then - Print the name of the thing we've found (
-print
).
Regarding -mtime +0
: On your AIX system, see the note regarding the semantics of -mtime
to determine whether to use -mtime +0
or -mtime +1
. If you want the UNIX03 behaviour, you should be using -mtime +0
to find files with a modification timestamp of more than 24 hours ago (and set the environment variables XPG_SUS_ENV
to ON
and XPG_UNIX98
to OFF
, in accordance with that note in the manual).
By default, find
outputs the pathnames of the found files. This means that you'll get filenames prepended by ./
from the above command. If you don't want that, then you will have to call the basename
utility for each found filename.
You can do that like this:
find . ! -name . -prune -type f -mtime +0 -exec basename ;
In comments you mention that you'd like to compress these files. For this, there is no need to call the basename
utility. Just call gzip
(or whatever compression utility you'd like to use) instead:
find . ! -name . -prune -type f -mtime +0 -exec gzip +
Depending on whether you'd like to do something further with these files, you may look for similar question on this site, e.g. Why is looping over find's output bad practice?
Also related:
- Understanding the -exec option of `find`
2
Comments are not for extended discussion; this conversation has been moved to chat.
– terdon♦
Mar 18 at 13:14
Is there any way using xargs to implement the same?
– Anony
Mar 18 at 13:37
@Anony Not in any way that would help I think. Also, this comment section was archived in a chat. Do consider using it. Also note that I've asked multiple times for the actual command that you are using. I can't debug anything without seeing it. Do not post further comments in this thread, but do feel welcome to use the chat.
– Kusalananda
Mar 18 at 13:41
1
Shouldn’t it be-mtime +0
? See Why does find -mtime +1 only return files older than 2 days?
– Melebius
Mar 19 at 7:29
@StéphaneChazelas Sorted. Though, thefind
on OpenBSD seems to have different semantics for-mtime
and you would have to use+1
there rather than+0
.
– Kusalananda
Mar 19 at 10:35
add a comment |
Assuming that the implementation of find
on your Unix has the -maxdepth
predicate (it's non-standard, but often available), the following find
command would do that:
find . -maxdepth 1 -type f -mtime +0
This would print the names of the regular files (i.e. not directories, sockets, named pipes etc.) whose modification timestamp was more than 24 hours ago to the terminal.
If -maxdepth
can't be used, then consider
find . ! -name . -prune -type f -mtime +0 -print
This means:
- If the current thing
find
is looking at is not.
(! -name .
), the current directory, then
Prune that path from the search path offind
(-prune
). This stopsfind
from even considering entering any subdirectories.- If the thing is a regular file (
-type f
), and - If its modification timestamp is older than 24 hours (
-mtime +0
), then - Print the name of the thing we've found (
-print
).
Regarding -mtime +0
: On your AIX system, see the note regarding the semantics of -mtime
to determine whether to use -mtime +0
or -mtime +1
. If you want the UNIX03 behaviour, you should be using -mtime +0
to find files with a modification timestamp of more than 24 hours ago (and set the environment variables XPG_SUS_ENV
to ON
and XPG_UNIX98
to OFF
, in accordance with that note in the manual).
By default, find
outputs the pathnames of the found files. This means that you'll get filenames prepended by ./
from the above command. If you don't want that, then you will have to call the basename
utility for each found filename.
You can do that like this:
find . ! -name . -prune -type f -mtime +0 -exec basename ;
In comments you mention that you'd like to compress these files. For this, there is no need to call the basename
utility. Just call gzip
(or whatever compression utility you'd like to use) instead:
find . ! -name . -prune -type f -mtime +0 -exec gzip +
Depending on whether you'd like to do something further with these files, you may look for similar question on this site, e.g. Why is looping over find's output bad practice?
Also related:
- Understanding the -exec option of `find`
Assuming that the implementation of find
on your Unix has the -maxdepth
predicate (it's non-standard, but often available), the following find
command would do that:
find . -maxdepth 1 -type f -mtime +0
This would print the names of the regular files (i.e. not directories, sockets, named pipes etc.) whose modification timestamp was more than 24 hours ago to the terminal.
If -maxdepth
can't be used, then consider
find . ! -name . -prune -type f -mtime +0 -print
This means:
- If the current thing
find
is looking at is not.
(! -name .
), the current directory, then
Prune that path from the search path offind
(-prune
). This stopsfind
from even considering entering any subdirectories.- If the thing is a regular file (
-type f
), and - If its modification timestamp is older than 24 hours (
-mtime +0
), then - Print the name of the thing we've found (
-print
).
Regarding -mtime +0
: On your AIX system, see the note regarding the semantics of -mtime
to determine whether to use -mtime +0
or -mtime +1
. If you want the UNIX03 behaviour, you should be using -mtime +0
to find files with a modification timestamp of more than 24 hours ago (and set the environment variables XPG_SUS_ENV
to ON
and XPG_UNIX98
to OFF
, in accordance with that note in the manual).
By default, find
outputs the pathnames of the found files. This means that you'll get filenames prepended by ./
from the above command. If you don't want that, then you will have to call the basename
utility for each found filename.
You can do that like this:
find . ! -name . -prune -type f -mtime +0 -exec basename ;
In comments you mention that you'd like to compress these files. For this, there is no need to call the basename
utility. Just call gzip
(or whatever compression utility you'd like to use) instead:
find . ! -name . -prune -type f -mtime +0 -exec gzip +
Depending on whether you'd like to do something further with these files, you may look for similar question on this site, e.g. Why is looping over find's output bad practice?
Also related:
- Understanding the -exec option of `find`
edited 2 days ago
answered Mar 18 at 11:03
KusalanandaKusalananda
137k17258426
137k17258426
2
Comments are not for extended discussion; this conversation has been moved to chat.
– terdon♦
Mar 18 at 13:14
Is there any way using xargs to implement the same?
– Anony
Mar 18 at 13:37
@Anony Not in any way that would help I think. Also, this comment section was archived in a chat. Do consider using it. Also note that I've asked multiple times for the actual command that you are using. I can't debug anything without seeing it. Do not post further comments in this thread, but do feel welcome to use the chat.
– Kusalananda
Mar 18 at 13:41
1
Shouldn’t it be-mtime +0
? See Why does find -mtime +1 only return files older than 2 days?
– Melebius
Mar 19 at 7:29
@StéphaneChazelas Sorted. Though, thefind
on OpenBSD seems to have different semantics for-mtime
and you would have to use+1
there rather than+0
.
– Kusalananda
Mar 19 at 10:35
add a comment |
2
Comments are not for extended discussion; this conversation has been moved to chat.
– terdon♦
Mar 18 at 13:14
Is there any way using xargs to implement the same?
– Anony
Mar 18 at 13:37
@Anony Not in any way that would help I think. Also, this comment section was archived in a chat. Do consider using it. Also note that I've asked multiple times for the actual command that you are using. I can't debug anything without seeing it. Do not post further comments in this thread, but do feel welcome to use the chat.
– Kusalananda
Mar 18 at 13:41
1
Shouldn’t it be-mtime +0
? See Why does find -mtime +1 only return files older than 2 days?
– Melebius
Mar 19 at 7:29
@StéphaneChazelas Sorted. Though, thefind
on OpenBSD seems to have different semantics for-mtime
and you would have to use+1
there rather than+0
.
– Kusalananda
Mar 19 at 10:35
2
2
Comments are not for extended discussion; this conversation has been moved to chat.
– terdon♦
Mar 18 at 13:14
Comments are not for extended discussion; this conversation has been moved to chat.
– terdon♦
Mar 18 at 13:14
Is there any way using xargs to implement the same?
– Anony
Mar 18 at 13:37
Is there any way using xargs to implement the same?
– Anony
Mar 18 at 13:37
@Anony Not in any way that would help I think. Also, this comment section was archived in a chat. Do consider using it. Also note that I've asked multiple times for the actual command that you are using. I can't debug anything without seeing it. Do not post further comments in this thread, but do feel welcome to use the chat.
– Kusalananda
Mar 18 at 13:41
@Anony Not in any way that would help I think. Also, this comment section was archived in a chat. Do consider using it. Also note that I've asked multiple times for the actual command that you are using. I can't debug anything without seeing it. Do not post further comments in this thread, but do feel welcome to use the chat.
– Kusalananda
Mar 18 at 13:41
1
1
Shouldn’t it be
-mtime +0
? See Why does find -mtime +1 only return files older than 2 days?– Melebius
Mar 19 at 7:29
Shouldn’t it be
-mtime +0
? See Why does find -mtime +1 only return files older than 2 days?– Melebius
Mar 19 at 7:29
@StéphaneChazelas Sorted. Though, the
find
on OpenBSD seems to have different semantics for -mtime
and you would have to use +1
there rather than +0
.– Kusalananda
Mar 19 at 10:35
@StéphaneChazelas Sorted. Though, the
find
on OpenBSD seems to have different semantics for -mtime
and you would have to use +1
there rather than +0
.– Kusalananda
Mar 19 at 10:35
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%2f506959%2fhow-can-i-get-files-using-find-command%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
4
Please always mention your operating system! You already wasted your time on Ask Ubuntu because you didn't tell us you were using AIX and now you have reposted here (which is fine, AIX is welcome here) and you still didn't tell us you're using AIX! I had to edit it in. The basic tools like
find
vary considerably between the different implementations, so you always need to tell us what OS you are using. The shell you are using, ksh in your case, is irrelevant.– terdon♦
Mar 18 at 13:13
Similar: delete folders older than 1 day
– Stéphane Chazelas
Mar 19 at 7:53