rubayeet
rubayeet

Reputation: 9400

Bash: File matching pattern works on Ubuntu but not on OS X

Let's say I have the following two files in my directory

- test.yaml
- test.yml

On Ubuntu, the following bash command lists both the files:

$ find .  -regex '.*\.ya?ml'
./test.yaml
./test.yml

However, on OS X the same command does not list any file:

$ find .  -regex '.*\.ya?ml' 

My question, what is the regular expression pattern that can passed to -regex param, so the command works on both platforms?

Upvotes: 1

Views: 70

Answers (1)

anubhava
anubhava

Reputation: 785856

find available on OSX requires -E for supporting extended regular expressions. On OSX following will work:

find -E .  -regex '.*\.ya?ml'

Following will also work on OSX without needing extended regex:

find .  -regex '.*\.ya\{0,1\}ml'

EDIT: If you want a common find for both systems then use:

find .  -regex '.*\.ya*ml'

Upvotes: 3

Related Questions