This command searches the current directory and all subdirectories downward from the current directory until it finds all matches to the <filename> and then displays their locations on your screen. You can also use regular expressions (see "Using Regular Expressions and Metacharacters") in your searches.find . -name <filename> -print
The following command line searches for files that have been changed after the time /tmp/file was last modified. If you use touch(1) to create /tmp/file with an old date, this command can help you find all files changed after that date.
You can use find to locate files and then to run another command on the found files. This example shows how to locate a file in a user's directory:find / -local -newer /tmp/file -print
In this example, the period (.) indicates the current directory, the -name option indicates that the next argument in quotes is the name of the file you are looking for, and the -print option tells find to display the pathname of the file when the file is located.cd /usr/people/trixie
find . -name 'missingfile' -print
The next example shows how to change the permissions on all the files in the current directory and in all subdirectories:
The option immediately following the find command is a period (.). This indicates to find that the search is to begin in the current directory and include all directories below the current one. The next flag, -name, indicates the name of the files that are being found. In this case, all files in the directory structure are selected through the use of the asterisk metacharacter (*). See "Using Regular Expressions and Metacharacters" for more information on metacharacters and regular expressions.find . -name '*' -local -exec chmod 644 {} \;
The -local option indicates to find that the search is limited to files that physically reside in the directory structure. This eliminates files and directories that are mounted via the Network File System (NFS). The -exec option causes find to execute the next argument as a command, in this case chmod 644. The braces, { }, refer to the current file that find is examining.
The last two characters in the command line are part of the chmod command that will be executed (with the -exec option) on all files that match the search parameters. The backslash (\) is necessary to keep the shell from interpreting the semicolon (;). The semicolon must be passed along to the chmod process. The semicolon indicates a carriage return in the chmod command.
The find command has several other useful options:
If you place a minus sign in front of onum, only the bits that are actually set in onum are compared with the file permission flags.
This command sequence preserves the symbolic links in the new directory as well as transparently cross file system boundaries.mkdir new_directory_name
cd the_directory_you_want_to_copy
find . -print | cpio -pdlmv new_directory_name