A few days ago a user of the forum asked us
how to search files by user from the console
, hence the idea of "‹"‹writing a small tutorial to
search
for
files according to the date of modification in Linux
. For this purpose we will use the
find
command, known for its great functionality and flexibility in Linux environments.
Searching according to the last date of modification of a file is simple, but we must know the appropriate syntax. It is a very useful type of search in different situations and that we should all know. I will show the different commands with their syntax.
How to search for files according to the modification date in Linux.
Search for files and folders that have been modified on the last day
, that is, files modified within the last 24 hours:
find -mtime -1
The number
-1
indicates a day, but we could use the number we wanted. For example, to
search
for
modified files within the last
week we would use 7 days with the command:
find -mtime -7
We can also specify minutes instead of days, but for this we would use the
-mmin
option. For example, to
search
for
modified files in the last 30 minutes
, we would use the command:
find -mmin -30
Complementary searches to the previous ones.
All the previous commands have their complements changing the symbol
-
by
+
. For example, in the first case, to
search
for
files that have been modified more than a day ago we
would use the command:
find -mtime +1
We can also
search for modified files more than 7 days ago
:
find -mtime +7
Or we can also specify a
search for files that have been modified more than 30 minutes ago
:
find -mmin +30
Sometimes it is useful to
indicate the path where we want you to search
, for example
find /home/TechnoWikis -mmin +30
or
restrict the search to a specific file extension
find -mtime +3 -name "*.php"
.
As always, it is advisable to have the find help page at hand, which we can access with the
man find
command and will show us all the options of this great search tool.