An action attribute can enhance that functionality and perform a particular task once a file is located. We have seen how to use the find command to display search results in your terminal window. Wildcards are useful if you only remember part of a filename, or are searching for files with a particular extension. In this case, the asterisk (the * sign) is used as a wildcard, meaning that it can stand in for any number of characters of any type. The system searches the current directory for regular files ( type –f ) that have an extension of. Single quotes ensure that the system interprets the request correctly.Įnter the following command to search for files with a specific extension, like. – require the use of single quotes around the name. Special characters – a wildcard, a period, a slash, etc. Standard letters and numerals are entered as a string of characters at the end of the command. Typically, the name of the file you’re looking for comes at the end of the command, after the location, options, and expressions. The find tool is going to the specified location for whatever string of characters you enter. The name attribute defines the object of your search. The system will search the current directory for any file with the name settings.txt.Ĭommands referencing the size of the searched items can be used individually to show all files larger than a certain size, smaller than a certain size, or within a defined range. This expression searches the location you’ve specified for a file with the name you type in the name field. The tilde character ~ is used to search the home directory of the current user: sudo find ~ Use Expressions with find CommandĮxpressions apply additional parameters to the find command search process. Įnter a slash /, and your system is going to search the entire hard drive: sudo find / to search the directory you’re currently in: sudo find. In our example, the search term is filename. The find command searches everything under the /home directory (including all user directories) for your search term. If you are not certain where you want to look, you can widen the search location.įor example, if you have two user accounts and you don’t remember which one you saved a file to, you can enter: sudo find /home filename This command searches the user account in the home directory. Searching for files based on their location string can be a simple command such as: sudo find /home/user filename The find command also enables you to define search parameters, options, and locations with a high level of accuracy. The find command lists all instances of the character string you included in your search. It can be used to control the behavior and optimize the search process. Options – This attribute is not a mandatory element of the find command.Name – Represents the string of text (or other data) you are searching for.Action – The a ction attribute executes a command on the search results.Expression – Tells find what category of information it’s supposed to look for.Location – Instructs find where to start looking for your search term.The basic syntax of the find command uses the following format: find Access to a terminal window/command line.In this article you learned about how to use the linux find command to search for files based on name, extension, size and type. test -type f -exec grep -l -i "login_scenarios" Sometimes you want to find a file and you don’t know its name, but you know it has a certain text inside it. If you want to search and list all files with a given name in multiple directories you can either start the search at root folder, or if you know the directories, you can specify them.Įxample: find. To find only directories, we need to use the -d option: find. To find only files, we need to use the -f option: find. test/results/failedTests.jpgįind files or directories with certain names To search and find files by a certain extension we use: find. In the above case, we are only searching within the “./test” directory. If you want to search for specific file(s) in a directory, we can use: find. Searching for a specific file in a directory If you know the name of a file but can’t remember the directory it’s in you can use the following command from the root directory: find. Let’s see some usage of the find command with examples: Searching for a file by name We can also use the find command to search for a particular text inside a file which we don’t know the name of. The Linux find command is a built in powerful tool that can be used to locate and manage files and directories based on a wide range of search criteria.įor example, we can find files by their name, extension, size, permissions, etc. In this post we will look at the linux find command and how to search and find files with different attributes.
0 Comments
Leave a Reply. |