Find man unix
SEE VIDEO BY TOPIC: Linux processes, init, fork/exec, ps, kill, fg, bg, jobsContent:
man command in Linux with Examples
In Unix-like and some other operating systems , find is a command-line utility that locates files based on some user -specified criteria and then applies some requested action on each matched object. It initiates a search from a desired starting location and then recursively traversing the nodes directories of a hierarchical structure typically a tree. The possible search criteria include a pattern to match against the filename or a time range to match against the modification time or access time of the file.
By default, find returns a list of all files below the current working directory , although users can limit the search to any desired maximum number of levels under the starting directory. The related locate programs use a database of indexed files obtained through find updated at regular intervals, typically by cron job to provide a faster method of searching the entire file system for files by name.
The two options control how the find command should treat symbolic links. The default behaviour is never to follow symbolic links. The -L flag will cause the find command to follow symbolic links. The -H flag will only follow symbolic links while processing the command line arguments. At least one path must precede the expression.
Expression elements are separated by the command-line argument boundary, usually represented as whitespace in shell syntax. They are evaluated from left to right. They can contain logical elements such as AND -and or -a and OR -or -o as well as predicates filters and actions. If the expression uses none of -print0 , -print , -exec , or -ok , find defaults to performing -print if the conditions test as true. Operators can be used to enhance the expressions of the find command.
Operators are listed in order of decreasing precedence:. This command searches the current working directory tree except the subdirectory tree ". We quote the! Real-world file systems often contain looped structures created through the use of hard or soft links.
The find utility shall detect infinite loops; that is, entering a previously visited directory that is an ancestor of the last file encountered. When it detects an infinite loop, find shall write a diagnostic message to standard error and shall either recover its position in the hierarchy or terminate.
This searches the current working directory tree for files whose names start with my. In newer versions of the program, the directory may be omitted, and it will imply the current working directory. This limits the results of the above search to only regular files, therefore excluding directories, special files, symbolic links, etc.
The previous examples created listings of results because, by default, find executes the -print action. Note that early versions of the find command had no default action at all; therefore the resulting list of files would be discarded, to the bewilderment of users.
This searches every directory for a regular file whose name is myfile and prints it to the screen. It is generally not a good idea to look for files this way. This can take a considerable amount of time, so it is best to specify the directory more precisely.
Some operating systems may mount dynamic file systems that are not congenial to find. More complex filenames including characters special to the shell may need to be enclosed in single quotes. You should always specify the directory to the deepest level you can remember. If you're doing this as a user other than root, you might want to ignore permission denied and any other errors.
The following example shows how to do this in the bash shell:. If you are a csh or tcsh user, you cannot redirect stderr without redirecting stdout as well. You can use sh to run the find command to get around this:. An alternate method when using csh or tcsh is to pipe the output from stdout and stderr into a grep command. This example shows how to suppress lines that contain permission denied errors.
The -ls operator prints extended information, and the example finds any regular file whose name ends with either 'jsp' or 'java'. Note that the parentheses are required. The -ls operator is not available on all versions of find. This command changes the permissions of all regular files whose names end with. For every regular file whose name ends in. The semicolon backslashed to avoid the shell interpreting it as a command separator indicates the end of the command.
Permission , usually shown as rw-r--r-- , gives the file owner full permission to read and write the file, while other users have read-only access. The -delete action is a GNU extension, and using it turns on -depth. So, if you are testing a find command with -print instead of -delete in order to figure out what will happen before going for it, you need to use -depth -print.
Delete empty files and print the names note that -empty is a vendor unique extension from GNU find that may not be available in all find implementations :. Without it, only the text found is printed.
GNU grep can be used on its own to perform this task:. The double quotes " " surrounding the search string and single quotes ' ' surrounding the braces are optional in this example, but needed to allow spaces and some other special characters in the string.
Quoting filenames which have English contractions demonstrates how this can get rather complicated, since a string with an apostrophe in it is easier to protect with double quotes:. Note that -iname is not in the standard and may not be supported by all implementations.
If the -iname switch is not supported on your system then workaround techniques may be possible such as:. Important arguments to note are in the tooltip that is displayed on mouse-over. The units should be one of [bckw], 'b' means byte blocks, 'c' means byte, 'k' means kilobytes and 'w' means 2-byte words. The size does not count indirect blocks, but it does count blocks in sparse files that are not actually allocated. From Wikipedia, the free encyclopedia. This article needs additional citations for verification.
Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. This section contains instructions, advice, or how-to content. The purpose of Wikipedia is to present facts, not to train.
Please help improve this article either by rewriting the how-to content or by moving it to Wikiversity , Wikibooks or Wikivoyage. September Retrieved Bell Labs. Retrieved 30 March Unix command-line interface programs and shell builtins. Hidden categories: Articles needing additional references from June All articles needing additional references Articles needing cleanup from September All pages needing cleanup Articles containing how-to sections.
This file documents the GNU utilities for finding files that match certain criteria and performing various operations on them. This file documents the GNU utilities for finding files that match certain criteria and performing various actions on them. This manual shows how to find files that meet criteria you specify, and how to perform various actions on the files that you find. The principal programs that you use to perform these tasks are find , locate , and xargs.
The find command allows users to search for files and take actions on them. It is highly flexible, allowing you to look for files and directories based on a variety of conditions. Optionally, it also allows you to take different types of actions on the results. In this article, we will understand how to work with the find command. We will also illustrate its usage through various examples throughout this article.
find(1) - Linux man page
In Unix-like and some other operating systems , find is a command-line utility that locates files based on some user -specified criteria and then applies some requested action on each matched object. It initiates a search from a desired starting location and then recursively traversing the nodes directories of a hierarchical structure typically a tree. The possible search criteria include a pattern to match against the filename or a time range to match against the modification time or access time of the file. By default, find returns a list of all files below the current working directory , although users can limit the search to any desired maximum number of levels under the starting directory. The related locate programs use a database of indexed files obtained through find updated at regular intervals, typically by cron job to provide a faster method of searching the entire file system for files by name. The two options control how the find command should treat symbolic links. The default behaviour is never to follow symbolic links.
Subscribe to RSS
On Unix-like operating systems, the find command searches for files and directories in a file system. Within each directory tree specified by the given path s, it evaluates the given expression from left to right, according to the rules of precedence see " Operators ", below until the outcome is known. At that point find moves on to the next path until all path s have been searched.
find(1) [v7 man page]
To use the find command, at the Unix prompt, enter:. Leave the double quotes in. The find command will begin looking in the starting directory you specify and proceed to search through all accessible subdirectories.
Search a folder hierarchy for filename s that meet a desired criteria: Name, Size, File Type - see examples. GNU find searches the directory tree rooted at each given file name by evaluating the given expression from left to right, according to the rules of precedence see Operators , until the outcome is known the left hand side is false for AND operations, true for OR , at which point find moves on to the next file name. The -H, -L and -P options control the treatment of symbolic links. That argument and any following arguments are taken to be the expression describing what is to be searched for. If no paths are given, the current directory is used. If no expression is given, the expression '-print' is used but you should probably consider using '-print0' instead, anyway.
Basic UNIX commands
The Linux find command is very powerful. It can search the entire filesystem to find files and directories according to the search criteria you specify. Besides using the find command to locate files, you can also use it to execute other Linux commands grep , mv , rm , etc. If you just want to see some examples and skip the reading, here are a little more than thirty find command examples to get you started. Almost every command is followed by a short description to explain the command; others are described more fully at the URLs shown:. If you know of any more good find commands to share, please leave a note in the Comments section below.
Linux and Unix find command tutorial with examples