简体   繁体   中英

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.

Use extglob:

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

It matches master3 optionally followed by .something

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

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

检查您的查找手册页,看看它是否具有-regex选项

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM