2

Please look at these two commands:

find ~/{Documents,Desktop,Downloads,Music,Videos} -mmin -120 -type f
and
find . ! -path "*opera*" ! -path "*mozilla*" ! -path "*google-chrome*" -mmin -120 -type f

While the first tells find to give results relating to specific folders, the second does the opposite. But is there a way to make the second command more compact or does ! path have to precede each folder?

The OS is Lubuntu 12.10.

1

You can use GNU find regular expressions (non standard extension):

find . -regextype posix-extended ! -regex '.*(opera|mozilla|google-chrome).*'

You can maybe use a different (more efficient) -regextype, I didn't check.

Chris Down's solution is not exactly the same thing as your second find command because it does not exclude your pattern from subdirectories (it would still find something like ./somedir/some-mozilla-dir).

The above command does not have this limitation.

  • Thanks for pointing out the limitation in my command, I missed it. – Chris Down Mar 26 '13 at 15:23
  • @ChrisDown You're welcome :) However, using zsh, something like setopt extendedglob and then **/*~*opera*~*mozilla*~*google-chrome* should match what you want to (~ means exclude). – Totor Mar 26 '13 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy