Chux
Chux

Reputation: 1227

Regular expression - Find ocurrences that has one string

Im trying to find all files modified during de last 24 hours in /var/www/vhost directory.

That is working ok with the find command, then, I want to filter the list because i don't want jpg files, jpeg files and so on.

Now i have this and it's working ok:

find /var/www/vhosts/ -ctime 0 -type f | grep  -ve ".jpg$" | grep -ve ".jpeg"

I guess (and know) there's a better solution to my problem.

Any help?

Upvotes: 1

Views: 90

Answers (3)

Fred Foo
Fred Foo

Reputation: 363517

Use -regex and ! (negation):

find $DIR -regextype posix-extended ! -regex '.*\.(gif|jpg|pdf|png)$'

Upvotes: 0

Vijay
Vijay

Reputation: 67211

change your find command itself to

find /var/www/vhosts/ -not \( -name "*.jpeg" -o -name "*.jpg" \) -ctime 0 -type f

Upvotes: 1

TomH
TomH

Reputation: 9220

You can do it all with one find command:

find /var/www/vhosts -ctime 0 -type f \! -iname \*.jpg \! -iname \*.jpeg

Upvotes: 0

Related Questions