Find command is most powerful command in linux to find files
as per our criteria. It is used not only
to search files but also to run different commands on those files. Mostly we
are searching files by modification time or access time of that file. So, in
this article, we will search files by this two parameters only. We will see
mtime and atime in detail with examples.
- To find files who accessed in last 7 days
To find files whose access time is newer i.e. in last 7 days
only. Then we can search those files by following command.
root@hello:~/ctier/examples#
find . -type f -mtime -7
|
This command will be helpful to get only files i.e. type
option will help to get files or directories if you put d instead of f then it
will search for directories. And mtime i.e. modification time should be last 7
days only then it should be -7 and if you want to do reverse i.e. you need all
files whose modification time is 7 days before i.e. do not display the files
whose modification time is last 7 days then use +7.
mtime option we can use with
multiple find commands option like –newer, -type, -name, -depth etc.
Examples:
- To find files whose access time is within last 7 days only
root@hello:~/ctier/examples# find
. -type f -atime -7
|
root@hello:~/ctier/examples# find
. -type f -atime +15
|
root@hello:~/ctier/examples# find
. –maxdepth 3 -type f –mtime -7
|
root@hello:~/ctier/examples# find
. –maxdepth 3 -type f –mtime-30 –atime
2
|
- maxdepth option is available but
instead of it, many times we need to use - depth option and it varies from OS
to OS.
Find atime and find mtime are two
mainly used options with find command. If you need more information or having
some doubts regarding this then please write us at: linuxconcepts@gmail.com
Write more on find command examples
ReplyDeletehow do you count the number of rows ex find . -atime 1 | ?????
ReplyDelete