Regex alternative to find files

When I attempt the regex alternative to find files in my downloads, especially, for this instance to get .csv extensions, I get nothing returned.

I know I can get these files with:

find . -name '*.csv'

However, none of my regex alternatives with find work, for example:

 find . -regextype sed -regex '.csv$'

Returns nothing even though it’s a working regular expression. Neither does the following:

find . -regextype sed -regex '(?<=\/)(.*?).csv$'

When my files look like:

./Campaigns (1).csv

>Solution :

You can do the following

find . -regextype sed -regex '.*\.csv'

What does this mean?

  • .* refers to the longest string containing any element in this pattern;
  • \.csv refers to the literal string .csv

Note how the dot needs to be escaped, otherwise it is seen as any character.

I believe this should work.

Leave a Reply