0

Now I want to find file size greater than 25MB and date previous 7 days, how to using or? Now I am writing like this:

find /var/lib/docker/ -type f ( -size +25M -or -mtime +7 ) -name *.log

but it is not working.

Dolphin
  • 609
  • Your text says "size greater than 25MB AND date previous 7 days" but your find command say "size greater than 25MB OR date previous 7 days". Which one is it? Also, always mention in what specific way things are not working. For example: "it finds the wrong files", or "it gives me the error (some error message)". – Kusalananda Apr 19 '20 at 07:02

1 Answers1

5

Assuming that you actually mean OR (your text says AND), your command looks correct apart from that the pattern *.log needs to be quoted. The ( and ) also needs to be quoted or escaped so that the shell doesn't think it's a subshell:

find /var/lib/docker/ -type f \( -size +25M -o -mtime +7 \) -name '*.log'

Using '(' ... ')' would also work, as would using double quotes.

If you don't quote *.log, the shell would try to expand that pattern against all filenames in the current directory before executing find.

In the command above, I've opted for using -o instead of the non-standard -or.

If you care about efficiency, you could rearrange the tests as

find /var/lib/docker/ -name '*.log' -type f \( -size +25M -o -mtime +7 \)

This means that find wouldn't have to use a stat call to get the size and timestamps of each file unless their names matches *.log.

Kusalananda
  • 333,661