PrepAway - Latest Free Exam Questions & Answers

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) ?

PrepAway - Latest Free Exam Questions & Answers

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 ‘.*’

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


Leave a Reply