The find
command allows you to find files within a range of dates.
For example, let's say you wish to find all files modified in the past
month, and show the file's size, modification date, and pathname. Use
this:
find . -type f -mtime -31 -printf '%10s %TY-%Tm-%Td %P\n'
Each flag is described here:
-type f
: restricts results to plain files; no directories or links-mtime 31
: restricts results to files less than 31 days old-printf '%10s %TY-%Tm-%Td %P\n'
: custom output format to show file size in bytes, modification date, and pathname relative to the directory given tofind
, which in this example is the current directory (.
)
Now if you wanted to find all files modified between 6 months and a
year ago, you would use two -mtime N
directives like so:
find . -type f -mtime +180 -mtime -365 -printf '%10s %TY-%Tm-%Td %P\n'
The changes from the first command, -mtime +180
, and -mtime -365
,
instruct find
to filter out files older (+
) than 180 days and
younger (-
) than 365 days.