Try:
find -maxdepth 1 -mtime +30 -type f \( -name "*.log*" -o -name "*.out*" \)
The problem was that find
binds logical-and tighter than logical-or. The parens counteract that.
Without the parens, find
is looking for files that match either (a) -mtime +30 -type f -name "*.log*"
or (b) -name "*.out*"
.
With the parens, find
is looking for files that (a) match -mtime +30 -type f
and (b) match either -name "*.log*"
or -name "*.out*"
.
Note that when you do -mtime <timespec>
, the <timespec>
checks the age of the file at the time find
was started.
Unless you run it in a very small directory tree, find
will take several milliseconds (if not seconds or hours) to crawl the directory tree and do a lstat()
on every file. So having a precision of shorter than a second doesn't necessarily make a lot of sense.
Also note that not all file systems support time stamps with subsecond granularity.
Having said that, there are a few options.
With the find
of many BSDs and the one from schily-tools
, you can do:
find . -atime -1s
To find files that have been last accessed less than one second ago (compared to when find
was started).
With zsh
:
ls -ld -- **/*(Dms-1)
For subsecond granularity, with GNU tools, you can use a reference file whose atime you set with touch
:
touch -ad '0.5 seconds ago' ../reference
find . -anewer ../reference
Or with recent versions of perl
:
perl -MTime::HiRes=lstat,clock_gettime -MFile::Find -le '
$start = clock_gettime(CLOCK_REALTIME) - 0.5;
find(
sub {
my @s = lstat $_;
print $File::Find::name if @s and $s[8] > $start
}, ".")'
Best Answer
You could use the recursive switch (
-R
) tols
along with the sort by time switch (-t
) and the reverse sort switch (-r
) to list out all the files in a directory tree. This will not sort all the files by their access/modify dates across sub-directories, but will sort them by this date within each sub-directory independently.Using a command such as this:
ls -ltrR <sometopdir>
.Example