Prakash
Prakash

Reputation: 279

find php file with x length or less than x length

I want to find php files with 3 characters long or less than it. eg ..php, a.php, cc.php, abc.php etc. I know how to find exactly x lenght of file by following command. For example if I want to find 3 characters long php files and dump all the result to a file I'll do

# find . -type f -name "???.php" >> results.txt

I just need a little tweak.

Upvotes: 0

Views: 60

Answers (2)

Reinstate Monica Please
Reinstate Monica Please

Reputation: 11613

globs should be good enough

find -type f \( -name "?.php" -o -name "??.php" -o -name "???.php" \)  >> results.txt

Or if you want regex

find -type f -regextype 'posix-basic' -regex '.*/[^/]\{1,3\}\.php$' >> results.txt

Upvotes: 1

Andreas Gnyp
Andreas Gnyp

Reputation: 1840

Maybe this is what you want?

find . -name "*.php" |grep "/.\{1,3\}\.php" >> results.txt

Upvotes: 0

Related Questions