There's a lot of documentation about the find command.
This page contains some of the best examples that I've seen.
Find all regular files (not directories or links, etc) starting from current directory.
find . -type f
-type t
True if the file is of the specified type. Possible file types
are as follows:
b block special
c character special
d directory
f regular file
l symbolic link
p FIFO
s socket
Numeric arguments to find can be prefixed with + or - if you want to find less than/greater than n instead of exactly n
Examples:
Less than 10 minutes old.
find . -mmin -10
More than 10 minutes old
find . -mmin +10
Less than 1 day old
find . -mtime -1
More than 1 day old
find . -mtime +1
Exactly 1 day old
find . -mtime 1
Accessed less than 1 minute ago
find . -amin -1
find . -size +100000c # find files w/size > 100,000 bytes find . -size -100000c # find files w/size < 100,000 bytes
Find files ending in .c, that contain foo them.
find . -name \*.c | xargs grep foo
Same thing, but print filename and line numbers of where you found 'foo'.
find . -name \*.c | xargs grep -n 'foo'
If you want to search for files that match X, then find Y in them, and can't remember the find/grep combinations, you can try one of these scripts:
find /path/to/directory -type f -print | wc -l
find /path/to/directory -type f -ls
From http://www.athabascau.ca/html/depts/compserv/webunit/HOWTO/find.htm#EX03
How to search for a string in a selection of files (-exec grep …).
find . -exec grep "www.athabasca" '{}' \; -print
This command will search in the current directory and all sub directories. All files that contain the string will have their path printed to standard output.
If you want to just find each file then pass it on for processing use the -q grep option. This finds the first occurrance of the search string. It then signals success to find and find continues searching for more files.
find . -exec grep -q "www.athabasca" '{}' \; -print
This command is very important for process a series of files that contain a specific string. You can then process each file appropriately. An example is find all html files with the string “www.athabascau.ca”. You can then process the files with a sed script to change those occurrances of “www.athabascau.ca” with “intra.athabascau.ca”.
find . -iname "*jpg" -exec mv {} . \;
You use the -prune option to tell find not to bother with certain directories. This can speed up your search considerably. You specify -prune after the expression that you don't want to see. For example:
FIXME
This should be its own page.
Use square braces to identify character groups. Characters are literal (do not need to be escaped).
# Find any of the characters between the [ and ] below in some_file grep '[*.\^$]' some_file # You can search for ] in a character group if the ] is the # first character after the opening brace. # Finds the ] as well as other characters in some_file. grep '[][*.\^$]' some_file