Regex / linux find command not working properly

Reference Information. I am trying to get the total number of lines of all code files (.html | .htm | .php | .js | .css) in my root web directory (recursively) by passing this output to xargs wc -l | grep total xargs wc -l | grep total .

 $ find . -regex '.+\.php' ./inc/db.php ./inc/userauth.php ./index.php .......... etc. $ find . -regex '.+\.js' ./inc/jquery-1.7.1.js ./inc/script.js $ find . -regex '.+\.(php|js)' (returns nothing) 

According to this ,

 abc(def|xyz) matches abcdef or abcxyz 

So you shouldn't .+\.(php|js) match all .php and .js files?

+4
source share
2 answers

find uses a different regex style, so you need to write \(js\|php\) instead of (js|php) .

+6
source
 find . -regex '.+\.\(php\|js\)' 

Escape characters that are special, although they depend on your shell (which is why I was zealous here).

+4
source

Source: https://habr.com/ru/post/1398118/


All Articles