4

I'd like to find all the files suffix with .md or .org

find ~ -iregex ".*\.md$"
find ~ -iregex ".*\.org$"

How could combine them?

0

2 Answers 2

5

Just concatenate your search like says in this answer :

find ~ -name "*.md" -o -name "*.org"

Explanation :

  • -name would do the search recursively (remove it if you don't want to have subdirectories result)
  • -o option represents an OR operator (it would execute both commands even if there is no .md file)
  • ~ is the path where you want to start the find execution; here, you begins at ~ (so /home/user where user is your username)

P.S : if you want to use (), you need to use the escape character \ like that :

find ~ \( -name "*.md" -o -name "*.org" \)

Both of these commands works, but the first is enough in this case.

P.P.S : in case that you want to find files that would got these extensions with uppercases, use the -iname option instead of -name option, like that :

find ~ -iname "*.md" -o -iname "*.org"

You would be able to find files named like README.MD for example, which aren't shown with the -name option

0
4
find ~ -regextype egrep -iregex ".*\.(md|org)"

Look into the docs of the regextype option to see the supported types of regular expressions. The egrep, posix-extended and maybe others understand the groups/alternatives in parentheses.

1
  • 1
    ... or ".*\.\(md\|org\)" with the default Emacs regextype Nov 18, 2019 at 12:56

Not the answer you're looking for? Browse other questions tagged .