Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix - Using find to List all .html files. (Do not use shell wildcards or the ls command)

I've tried 'find -name .html$', 'find -name .html\>'.
None worked.

I'd like to know why these two are wrong and what's the right one to use with no wildcards?

like image 722
Zoe Avatar asked Nov 05 '25 15:11

Zoe


2 Answers

What you needed was

find -name '*.html'

Or for regex:

find -regex '.*/.*\.html'

To ignore case, use -iname or -iregex:

find -iname '*.html'
find -iregex '.*/.*\.html'

Manual for -name:

   -name pattern
          Base of file name (the path with the leading directories
          removed) matches shell pattern pattern.  The metacharacters
          (`*', `?', and `[]') match a `.' at the start of the base name
          (this is a change in findutils-4.2.2; see section STANDARDS CON‐
          FORMANCE below).  To ignore a directory and the files under it,
          use -prune; see an example in the description of -path.  Braces
          are not recognised as being special, despite the fact that some
          shells including Bash imbue braces with a special meaning in
          shell patterns.  The filename matching is performed with the use
          of the fnmatch(3) library function.   Don't forget to enclose
          the pattern in quotes in order to protect it from expansion by
          the shell.
like image 63
konsolebox Avatar answered Nov 09 '25 00:11

konsolebox


find . -name '*.html'

You have to single quote the wildcard to keep the shell from globbing it when passing it to find.

like image 28
Bill Avatar answered Nov 08 '25 22:11

Bill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!