Elfendos
Elfendos

Reputation: 13

Shell script can't use logical or with find command

I have a script that deletes *.log or *.txt files either more than 10 MB or more than 15 days old. I wrote the code but cannot put -or between *log and *txt. How can I do that?

find . -iname "*.txt" -type f \( -mtime +15 -or -size +10000k \)

Upvotes: 0

Views: 57

Answers (2)

Jonathan Leffler
Jonathan Leffler

Reputation: 754060

You need to think in terms of:

  • -iname "*.txt" or -iname "*.log"
  • and
  • -type f
  • and
  • -mtime +15 or -size +10000k

which translates to:

find . \( -iname "*.txt" -or -iname "*.log" \) -type f \( -mtime +15 -or -size +10000k \)

The default conjunction between terms is 'and' so there's no need for explicit -and operations.

Upvotes: 1

champbell
champbell

Reputation: 31

Have you tried -o? Can you elaborate on the shell you're using?

Upvotes: 0

Related Questions