chop
chop

Reputation: 471

Using bash find how can I ignore all file extensions if present?

Say I have this in a directory:

master3.txt
master3
master3old
anotherFile

and I need to use find to return:

master3.txt
master3

Basically it means using find and ignoring file extensions if present. The key thing in this example is to not return "master3old"

I want to use find on Mac OS X so I can then run -exec cp on the result.

Upvotes: 0

Views: 149

Answers (3)

glenn jackman
glenn jackman

Reputation: 246837

check your find man page, see if it has the -regex option

find . -regex '.*/master3\(\..*\)?'

Upvotes: 0

that other guy
that other guy

Reputation: 123480

Use extglob:

shopt -s extglob
cp master3?(.*) /somewhere

It matches master3 optionally followed by .something

Upvotes: 2

unxnut
unxnut

Reputation: 8839

find $DIR -name "master3*" | grep "master3\>" | xargs 

where $DIR is the directory being searched. \> indicates the end of word.

Upvotes: 1

Related Questions