#tested and working location="/maildir/user/.mailing-lists.workaround-chitchat/cur" location=${location%/*} location=${location##*/} echo "$location" #need to convert the above, so it can be used in find -exec echo "/maildir/user/.mailing-lists.workaround-chitchat/cur" | grep --regexp '????' find "$maildir' -type d -name cur -exec grep --regexp '????' '{}' \;