Search code examples
bashfind

simplify find command with 0 or 1 time repeat pattern


How can I simplify below find command with pattern:

find . -type d -name symbols -o -name symbol

The pattern is 'symbol' + 0 or 1 's'.


Solution

  • You can use a -regex, but it must match the whole path, so you need to prepend .*/ to match the path.

    find . -type d -regex '.*/symbols?'