find path ...
/dev/null
by using the STDERR redirection operator:find path ... 2> /dev/null
-or
, -o
, -and
, -not
\( expression \)
(note the space before and after the expression)$ find . \( -name file1 -or -name folder1 \) -ls
$ find . \( -name file1 -o -name folder1 \) -ls
$ find . \( -name file1 -and -name folder1 \) -ls
$ find . \( -name file1 -not -name folder1 \) -ls
-exec
, -ok
-exec
option executes the command on each file found (or directory), without asking for confirmation.-ok
option ask for confirmation before executing the command on each file found (or directory).
You can confirm the execution of the command by typing y and pressing Enter otherwise press Enter to skip the execution of the command.$ find . -exec command {} \;
$ find . -ok command {} \;
$ find . -exec echo {} \; ./folder1 ./folder2
$ find . -exec echo {} \+ ./folder1 ./folder2
$ find . -type f
$ find . -type d
$ find . -type f -name 'file1'
$ find . -type d -name 'folder1'
.c
:
$ find . -type f \! -name "*.c"
.c
:
$ find . \! \( -type f -name "*.c" \)
.c
:
$ find . \( -type d -or -name "*.c" \)
$ find . -type f -name '*file*' $ find . -type f | grep "file"
$ find . -type d -name '*folder*' $ find . -type d | grep "folder"
$ find . -type f | xargs grep -l "bar"
$ find . -type f -exec ls -al {} \; | grep foo
$ find . -type f -name "*.jar" -exec jar -tf {} \; | grep "MANIFEST.MF"
$ for i in `find . -type f -name "*.jar"`; do echo $i; jar -tf $i | grep "MANIFEST.MF"; done
$ find . -type f -delete $ find . -type f -exec rm -f {} \; $ find . -type d -exec rm -rf {} \; $ find . -type f -print0 | xargs -0 rm
$ find . -type f -exec sed -i 's/bar/foo/g' {} \; $ find . -type f -exec sed -i 's/\#\!\/bin\/sh/\#\!\/bin\/bash/g' {} \;
$ find . -type f -exec sed -i '' -e 's/bar/foo/g' {} \;
for i in `find . -type d -name "foo"`; do folderName=$(dirname "$i"); mv $folderName/foo $folderName/bar; done
$ find . -type d -name "target" -exec rm -rf {} \; $ find . -type d -name ".settings" -exec rm -rf {} \; $ find . -type f -name ".classpath" -exec rm {} \; $ find . -type f -name ".project" -exec rm {} \; #$ find . -type f \( -name ".classpath" -o -name ".project" \) -exec rm -rf {} \; $ find . -type f -name "*~" -exec rm {} \; $ find . -type f -name ".directory" -exec rm {} \; #$ find . -type f \( -name "*~" -o -name ".directory" \) -exec rm -rf {} \; $ find . -type d -name ".svn" -exec rm -rf {} \;
-type t |True if the file is of the specified type t. -name pattern |True if the last component of the pathname being examined matches pattern. |Special shell pattern matching characters ("[", "]", "*", and "?") may be used as part of pattern. |These characters may be matched explicitly by escaping them with a backslash ("\"). -iname pattern |Like -name, but the match is case insensitive. -path pattern |True if the pathname being examined matches pattern. |Special shell pattern matching characters ("[", "]", "*", and "?") may be used as part of pattern. |These characters may be matched explicitly by escaping them with a backslash ("\"). |Slashes ("/") are treated as normal characters and do not have to be matched explicitly. -ipath pattern |Like -path, but the match is case insensitive. -regex pattern |True if the whole path of the file matches pattern using regular expression. |To match a file named "./foo/xyzzy", you can use the regular expression ".*/[xyz]*" or ".*/foo/.*", but not "xyzzy" or "/foo/". -iregex pattern |Like -regex, but the match is case insensitive. -empty |True if the current file or directory is empty. -depth n |True if the depth of the file relative to the starting point of the traversal is n. |1 means the starting directory.
-mmin n |True if the file is last modified exactly n minutes ago (use +/- for more/less than n minutes). -mtime [+-]n[smhdw] |True if the file is last modified exactly n units ago (use +/- for more/less than n units). |Any number of units may be combined in one -mtime, -Btime, -atime, or -ctime argument, for example, '-1h30m'. -Bmin [+-]n |True if the file is created exactly n minutes ago (use +/- for more/less than n minutes). -Btime [+-]n[smhdw] |True if the file is created exactly n units ago (use +/- for more/less than n units). -amin [+-]n |True if the file is last accessed exactly n minutes ago (use +/- for more/less than n minutes). -atime [+-]n[smhdw] |True if the file is last accessed exactly n units ago (use +/- for more/less than n units). -cmin [+-]n |True if the file is last changed exactly n minutes ago (use +/- for more/less than n minutes). -ctime [+-]n[smhdw] |True if the file is last changed exactly n units ago (use +/- for more/less than n units).
-size [+-]n[ckMGTP] |True if the file's size is exactly n units (use +/- for more/less than n units). |If no unit specified, the file's size, will be rounded up, in 512-byte blocks.
-user uname |True if the file belongs to the user uname. |If uname is numeric and there is no such user name, then uname is treated as a user ID. |If the user doesn't exist you get this error: "find: -user: uname: no such user". -group gname |True if the file belongs to the group gname. |If gname is numeric and there is no such group name, then gname is treated as a group ID. |If the group doesn't exist you get this error: "find: -group: gname: no such group". -nouser |True if the file belongs to an unknown user. -nogroup |True if the file belongs to an unknown group.
-ls |Always returns true. |The following information for the current file is written to standard output: |its inode number, size in 512-byte blocks, file permissions, number of hard links, owner, group, size in bytes, last modification time, and pathname. |If the file is a block or character special file, the device number will be displayed instead of the size in bytes. |If the file is a symbolic link, the pathname of the linked-to file will be displayed preceded by "->". |The format is identical to that produced by "ls -dgils". -print |Always returns true. |It prints the pathname of the current file to standard output. -print0 |Always returns true. |It prints the pathname of the current file to standard output, followed by an ASCII NUL character (character code 0). -delete |Delete found files and/or directories. |Always returns true. |This executes from the current working directory as find recurses down the tree. |It will not attempt to delete a filename with a "/" character in its pathname relative to "." for security reasons. |If you search for directories only, the delete action won't delete a directory if it's not empty. -exec utility [argument ...] ; |True if the program named utility returns a zero value as its exit status. |Optional arguments may be passed to the utility. |The expression must be terminated by a semicolon (";"). |If you invoke find from a shell you may need to quote the semicolon if the shell would otherwise treat it as a control operator. |If the string "{}" appears anywhere in the utility name or the arguments it is replaced by the pathname of the current file. |Utility will be executed from the directory from which find was executed. |Utility and arguments are not subject to the further expansion of shell patterns and constructs. -exec utility [argument ...] {} + |Same as -exec, except that "{}" is replaced with as many pathnames as possible for each invocation of utility. |This behaviour is similar to that of xargs. -ok utility [argument ...] ; |Same as -exec, except that find requests user affirmation for the execution of the utility by printing a message to the terminal and reading a response. |If the response is not affirmative ('y'), the command is not executed and the value of the -ok expression is false.
( expression ) |This evaluates to true if the parenthesized expression evaluates to true. ! expression -not expression |This is the unary NOT operator. |It evaluates to true if the expression is false. -false |Always false. -true |Always true. expression -and expression expression expression |The -and operator is the logical AND operator. |As it is implied by the juxtaposition of two expressions it does not have to be specified. |The expression evaluates to true if both expressions are true. |The second expression is not evaluated if the first expression is false. expression -or expression |The -or operator is the logical OR operator. |The expression evaluates to true if either the first or the second expression is true. |The second expression is not evaluated if the first expression is true.
+{n}: a plus sign (+) means 'more than n' (+3: more than 3) -{n}: a minus sign (-) means `less than n' (-3: less than 3) {n}: means 'exactly n' (3: exactly 3)
s: second m: minute (60 seconds) h: hour (60 minutes) d: day (24 hours) (default) w: week (7 days)
c: bytes k: kilobytes (1024 bytes) M: megabytes (1024 kilobytes) G: gigabytes (1024 megabytes) T: terabytes (1024 gigabytes) P: petabytes (1024 terabytes)
f: regular file d: directory l: symbolic link c: character special b: block special p: FIFO s: socket