![]() ![]() This is very useful when dealing with full file systems and trying to find large files that are filling up a disk. To find all files in /tmp that are smaller than 1 GB: find /tmp -size -1Gįind all files that are 1MB in size: find / -size 1M These are denoted by a plus or minus sign before the size specification.įinding files in your home directory larger than 50 MB: find ~/ -size +50M ![]() The size option accepts several different units.Īlong with the different units you also have greater than or less than options. To find a file based on size, you can use the -size switch. To find all the directories in your home: find ~/ -type d Finding Files by Size In order to specify a type, simply call the -type switch followed by the letter of your choice.įor example, to find all regular files in your home directory, run the following command: find ~/ -type f Let's take a look at how to use those most popular file type searches. You can use the -type switch to specify several different file types.Īlthough all of the above are supported, typically only f,d and l are popular options. This will allow find to use the wildcards in it's search instead of it being expanded by the parent shell and throwing an error. It is best to always escape or wrap wildcards in quotes. txt extension you can use the asterisks wildcard like so: find /usr -iname '*.txt' For example, if you wanted to find all files with a. $ find /usr -iname words.txtĪs mentioned above, you can use wildcards to expand your search to multiple possible matches. In order to make it case insensitive you can change it to -iname. $ find /usr -name Words.txtīy default the -name switch is case sensitive. Here is an example search for a file called Words.txt in the /usr directory. Using the -name switch, you can specify a name that you are looking for and find will search the provided path for a match. Finding a File by Nameįind is most commonly used to find a file by name, or part of it's name. In the following sections we will discuss how to use multiple tests to narrow your search and also how to take action on matched files. In this section we will discuss the tests and show some examples on how to use them. There are tests to match by name, file size, permissions and so on. The find command offers several built-in tests that help match files while searching. For more information read " Standard Wildcards and Globbing Patterns in Linux". We will touch on how to use these concepts in this article. Although covering file globbing is outside the scope of this article, it is important that you know it is available. Using Wildcards and GlobbingĪny expression passed to the find command can use file globbing / wildcards. The default action is to print matched files to standard output (STDOUT). This can be built in actions like delete, or expanded using xargs or exec. ActionsĪn action or set of actions to take on the files that are found or matched. Several expressions can be used to narrow your search results. The expression can be a simple name, a wildcard or a very complex expression with logical control operators. The expression is part of the command describes the criteria to match when searching for files. Meaning, it will look inside all directories and sub-directories in the path provided. You can provide multiple paths and find will search each one recursively. -H = Do not follow symbolic links except while processing the command line arguments.Ī path is a starting point in the filesystem for the search.-P = Never follow symbolic links (default behavior).If used they must appear before the first path. The find command only has five actual options (-H, -L, -P, -D, -O). Let's take a closer look at these, which will help fully understand how to use the find command. In the basic form, the find command takes options, a path to search, an expression to search for and an optional action to take when it finds a match. Prompt for Approval Before Executing Commands.Execute Commands from Subdirectory Containing Matched File.Listing Matched Files with Find Command. ![]()
0 Comments
Leave a Reply. |