which argument to the -name flag will match files or directories beginning with a ‘.’ (period)

With the find command, which argument to the -name flag will match files or directories beginning with a ‘.’ (period) ?

With the find command, which argument to the -name flag will match files or directories beginning with a ‘.’ (period) ?

Answer: [.]*

Explanation/Reference:
From the man pages:
-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 CONFORMANCE 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.

—————–
This will not work in the unlikely event that a file exists that is actually named “[.]<anything>”. So it is always better to enclose the search pattern in quotation marks to prevent the shell from expanding the pattern: find -name ‘.*’



Leave a Reply 3

Your email address will not be published. Required fields are marked *


Ralph

Ralph

.\* will also work.

kimou XV3

kimou XV3

‘.*’ will work too ^^

kimou XV3

kimou XV3

Sorry it was already write in the end of the explanation.