If you have several file names that contain a common string, say ‘VM’, the find command in this scenario will be as: find -name '*VM*' Find files with a matching pattern In the same way, you can also search for files with the same name but with any extension of three characters as: find ~ -name "abc.?" Find files with the same name but any extension Say, for instance, you are looking for all the configuration files on your system that end with the '.conf' extension: find /etc -type f -name "*.conf" | grep nf Find files with a certain extension You can also filter files that follow a given pattern. Searching for Files With a Particular Pattern The name of the file can be composed of wildcards as you will see later in this guide. The -name option is case-sensitive in contrast to the -iname option, so you are going to get files with the exact name.įor example, let us look for a file with the name abc.txt : find -name abc.txt Using the find command, you get both files in the results: find -iname abc.txt Find files with their name while ignoring the case Searching for Files Using their Exact Name Both of them have the same name but different cases. The -iname option looks for a file regardless of its case.įor example, suppose you have two files abc.txt and ABC.txt. Looking for a file with its name is a commonly used operation with the find command. If the file path is not specified, it searches in the current directory and its sub-directories. It has the following format: find path pattern The utility ‘find’ looks for files that match a certain set of parameters like the file’s name, its modification date, its extension, etc. Let’s first start with an overview of the find command. Excluding certain files from the search results.īesides these, I'll also show how to use the grep command with the output from the find command.Searching files for a particular pattern.I'll explain how to use the ‘find’ command for: The find command is extremely versatile and has way too many usages but here I'll focus on finding files by their name. Most common and most reliable way is to use the find command. There are multiple ways to find files in the Linux command line. Most often, you are looking for a file on Linux and you do not exactly know its true location on the system disk.
0 Comments
Leave a Reply. |