Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.