Reputation: 471
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
Reputation: 246837
check your find man page, see if it has the -regex
option
find . -regex '.*/master3\(\..*\)?'
Upvotes: 0
Reputation: 123480
Use extglob:
shopt -s extglob
cp master3?(.*) /somewhere
It matches master3
optionally followed by .something
Upvotes: 2
Reputation: 8839
find $DIR -name "master3*" | grep "master3\>" | xargs
where $DIR
is the directory being searched. \>
indicates the end of word.
Upvotes: 1