How search for files using regex in linux shell script

RegexLinuxShellSearch

Regex Problem Overview


Suppose, I want to search for files having python in filename in it, in all sub directories of linux, from a shell script. How can I search in all locations using regex?

Regex Solutions


Solution 1 - Regex

Find all .py files.

find / -name '*.py'

Find files with the word "python" in the name.

find / -name '*python*'

Same as above but case-insensitive.

find / -iname '*python*'

Regex match, more flexible. Find both .py files and files with the word "python" in the name.

find / -regex '.*python.*\|.*\.py'

Solution 2 - Regex

If simple shell regexps will suffice, then you can use find

find /linux -name "*python*"

Otherwise, I'd say use ack (http://betterthangrep.com/)

Solution 3 - Regex

find / -name "python"

[filler text to meet min.]

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMahakaalView Question on Stackoverflow
Solution 1 - RegexJohn KugelmanView Answer on Stackoverflow
Solution 2 - RegexMalcolm BoxView Answer on Stackoverflow
Solution 3 - RegexCrayon ViolentView Answer on Stackoverflow