Find command: Exclude / Ignore Files ( Ignore Hidden .dot Files )
Q. How do I ignore hidden .dot files while searching for files? How do I ignore or exclude certain files while running Linux / UNIX find command?
A. Find command support standard UNIX regex to match or exclude files. You can write complex queries easily with regex.
Find command and logical operators
Find any file whose name ends with either 'c' or 'asm', enter:
$ find . -type f \( -iname "*.c" -or -iname "*.asm" \)
The parentheses must be escaped with a backslash, "\(" and "\)", to prevent them from being interpreted as special shell characters. The -type f option force to only search files and not directories. The or operator either find .c or .asm file.
Understanding find command operators
Operators build a complex expression from tests and actions. The operators are, in order of decreasing precedence:
| ( expr ) | Force precedence. True if expr is true |
| expr -not expr |
True if expr is false. In some shells, it is necessary to protect the ‘!’ from shell interpretation by quoting it. |
| expr1 -and expr2 | And; expr2 is not evaluated if expr1 is false. |
| expr1 -or expr2 | Or; expr2 is not evaluated if expr1 is true. |
WARNING! The '-or', '-and', and '-not' operator are not available on all versions of find. Usually GNU find supports all options. Refer your local find command man page for more information.How do I ignore hidden .dot files while searching for files?
Find *.txt file but ignore hidden .txt file such as .vimrc or .data.txt file:
$ find . -type f \( -iname "*.txt" ! -iname ".*" \)
Find all .dot files but ignore .htaccess file:
$ find . -type f \( -iname ".*" ! -iname ".htaccess" \)
E-mail
Print
Can't find an answer to your question? Contact us
Related Other Helpful FAQs:
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: dot files, expression, find command, find command examples, find command operators, find command regex, gnu, iname, Linux, logical operators, parentheses, search files, shell, UNIX, unix regex



Recent Comments
Yesterday ~ 17 Comments
Yesterday ~ 5 Comments
Yesterday ~ 11 Comments
11/30/2008 03:50 pm (2 days ago) ~ 24 Comments
11/30/2008 11:51 am (2 days ago) ~ 6 Comments