Mahakaal Mahakaal - 19 days ago 5
Bash Question

how search for files using regex in linux shell script

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?

Answer

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'
Comments