![]() ![]() Here you need to use both the name and type options on the CLI as: find -type f \( -name "*.txt" -o -name "*.msi" \) Search for multiple files and multiple patterns Suppose you want to find multiple files in a directory having. ![]() You can also search in multiple directories by specifying them on the CLI: find ~/Desktop/example1/ ~/Desktop/example2/ -name 'abc*.*' Find files in multiple directories Searching for Multiple Files and Multiple Patterns So far, we have used a single directory (the home directory) with the ‘find’ command. 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. That's "almost the same" thing, and not "exactly the same" thing because there can be unexpected differences with shell expansions and file name globbing.Most often, you are looking for a file on Linux and you do not exactly know its true location on the system disk. This achieves almost the same thing as straightforward piping. To address this shortcoming the xargs command can be used to parcel up piped input and to feed it into other commands as though they were command-line parameters to that command. Related: How to Use the xargs Command on Linux The design principle of making a program do one thing and do it well, and to expect that its output could be the input of another program-even an as yet unwritten program-is often described as the "Unix philosophy." And yet some core utilities, like mkdir The principle of piping the output of one command into another command is a core characteristic of Unix-derived operating systems. If we can take the output of the find command and use it automatically as the input of other commands, we can make something happen to the files and directories that find uncovers for us. But there's a way to leverage that power and take things to another level. The humble find command really packs some power. Related: How to Use All Linux's Search CommandsĪll of that is fantastically useful. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |