Monday, June 8, 2015

Searching for files on Linux or UNIX

Here are some example on how to search for different files based on their extensions (or on some arbitrary naming requirement) with a single find(1) statement.

Find all C source files:
$ find . -name '*.c'
Find all C source and header files:
$ find . -name '*.[ch]'
Find all C source and header files as well as all Java files:
$ find . -name '*.[ch]' -print -o -name '*.java' -print
Same as the last example but removing SCCS files
$ find . -name 'SCCS' -prune -o -name '*.[ch]' -print -o -name '*.java' -print

No comments:

Post a Comment