How can I get files using find command












2















How to use find command to get only files from the current directory (excluding subdirectories and its files) older than a day on AIX?










share|improve this question




















  • 3





    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
    15 hours ago
















2















How to use find command to get only files from the current directory (excluding subdirectories and its files) older than a day on AIX?










share|improve this question




















  • 3





    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
    15 hours ago














2












2








2








How to use find command to get only files from the current directory (excluding subdirectories and its files) older than a day on AIX?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 15 hours ago









terdon

132k32262441




132k32262441










asked 17 hours ago









AnonyAnony

1191




1191








  • 3





    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
    15 hours ago














  • 3





    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
    15 hours ago








3




3





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
15 hours ago





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
15 hours ago










1 Answer
1






active

oldest

votes


















10














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 +1


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 . ( -type d ! -name . -prune ) -o -type f -mtime +1 -print


This means:




  1. If the current thing find is looking at is a directory (-type d), and

  2. If its name is not . (! -name .), i.e. it's a subdirectory, then


  3. Prune that directory from the search path of find (-prune). This stops find from even considering anything beneath subdirectories.


Otherwise (-o):




  1. If the thing is a regular file (-type f), and

  2. If its modification timestamp is older than 24 hours (-mtime +1), then

  3. Print the name of the thing we've found (-print).


The parentheses are there for precedence between the two sets of tests. They need to be escaped as they would otherwise be handled by the shell (as defining a sub-shell).



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 . ( -type d ! -name . -prune ) -o -type f -mtime +1 -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 . ( -type d ! -name . -prune ) -o -type f -mtime +1 -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`






share|improve this answer





















  • 2





    Comments are not for extended discussion; this conversation has been moved to chat.

    – terdon
    15 hours ago











  • Is there any way using xargs to implement the same?

    – Anony
    14 hours ago











  • @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
    14 hours ago













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
});


}
});














draft saved

draft discarded


















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









10














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 +1


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 . ( -type d ! -name . -prune ) -o -type f -mtime +1 -print


This means:




  1. If the current thing find is looking at is a directory (-type d), and

  2. If its name is not . (! -name .), i.e. it's a subdirectory, then


  3. Prune that directory from the search path of find (-prune). This stops find from even considering anything beneath subdirectories.


Otherwise (-o):




  1. If the thing is a regular file (-type f), and

  2. If its modification timestamp is older than 24 hours (-mtime +1), then

  3. Print the name of the thing we've found (-print).


The parentheses are there for precedence between the two sets of tests. They need to be escaped as they would otherwise be handled by the shell (as defining a sub-shell).



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 . ( -type d ! -name . -prune ) -o -type f -mtime +1 -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 . ( -type d ! -name . -prune ) -o -type f -mtime +1 -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`






share|improve this answer





















  • 2





    Comments are not for extended discussion; this conversation has been moved to chat.

    – terdon
    15 hours ago











  • Is there any way using xargs to implement the same?

    – Anony
    14 hours ago











  • @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
    14 hours ago


















10














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 +1


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 . ( -type d ! -name . -prune ) -o -type f -mtime +1 -print


This means:




  1. If the current thing find is looking at is a directory (-type d), and

  2. If its name is not . (! -name .), i.e. it's a subdirectory, then


  3. Prune that directory from the search path of find (-prune). This stops find from even considering anything beneath subdirectories.


Otherwise (-o):




  1. If the thing is a regular file (-type f), and

  2. If its modification timestamp is older than 24 hours (-mtime +1), then

  3. Print the name of the thing we've found (-print).


The parentheses are there for precedence between the two sets of tests. They need to be escaped as they would otherwise be handled by the shell (as defining a sub-shell).



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 . ( -type d ! -name . -prune ) -o -type f -mtime +1 -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 . ( -type d ! -name . -prune ) -o -type f -mtime +1 -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`






share|improve this answer





















  • 2





    Comments are not for extended discussion; this conversation has been moved to chat.

    – terdon
    15 hours ago











  • Is there any way using xargs to implement the same?

    – Anony
    14 hours ago











  • @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
    14 hours ago
















10












10








10







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 +1


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 . ( -type d ! -name . -prune ) -o -type f -mtime +1 -print


This means:




  1. If the current thing find is looking at is a directory (-type d), and

  2. If its name is not . (! -name .), i.e. it's a subdirectory, then


  3. Prune that directory from the search path of find (-prune). This stops find from even considering anything beneath subdirectories.


Otherwise (-o):




  1. If the thing is a regular file (-type f), and

  2. If its modification timestamp is older than 24 hours (-mtime +1), then

  3. Print the name of the thing we've found (-print).


The parentheses are there for precedence between the two sets of tests. They need to be escaped as they would otherwise be handled by the shell (as defining a sub-shell).



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 . ( -type d ! -name . -prune ) -o -type f -mtime +1 -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 . ( -type d ! -name . -prune ) -o -type f -mtime +1 -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`






share|improve this answer















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 +1


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 . ( -type d ! -name . -prune ) -o -type f -mtime +1 -print


This means:




  1. If the current thing find is looking at is a directory (-type d), and

  2. If its name is not . (! -name .), i.e. it's a subdirectory, then


  3. Prune that directory from the search path of find (-prune). This stops find from even considering anything beneath subdirectories.


Otherwise (-o):




  1. If the thing is a regular file (-type f), and

  2. If its modification timestamp is older than 24 hours (-mtime +1), then

  3. Print the name of the thing we've found (-print).


The parentheses are there for precedence between the two sets of tests. They need to be escaped as they would otherwise be handled by the shell (as defining a sub-shell).



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 . ( -type d ! -name . -prune ) -o -type f -mtime +1 -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 . ( -type d ! -name . -prune ) -o -type f -mtime +1 -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`







share|improve this answer














share|improve this answer



share|improve this answer








edited 15 hours ago

























answered 17 hours ago









KusalanandaKusalananda

136k17257425




136k17257425








  • 2





    Comments are not for extended discussion; this conversation has been moved to chat.

    – terdon
    15 hours ago











  • Is there any way using xargs to implement the same?

    – Anony
    14 hours ago











  • @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
    14 hours ago
















  • 2





    Comments are not for extended discussion; this conversation has been moved to chat.

    – terdon
    15 hours ago











  • Is there any way using xargs to implement the same?

    – Anony
    14 hours ago











  • @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
    14 hours ago










2




2





Comments are not for extended discussion; this conversation has been moved to chat.

– terdon
15 hours ago





Comments are not for extended discussion; this conversation has been moved to chat.

– terdon
15 hours ago













Is there any way using xargs to implement the same?

– Anony
14 hours ago





Is there any way using xargs to implement the same?

– Anony
14 hours ago













@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
14 hours ago







@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
14 hours ago




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

數位音樂下載

When can things happen in Etherscan, such as the picture below?

格利澤436b