What are Wild Cards
Wildcards are commonly used in computer programming and in various computer applications, such as text editors, search engines, and command-line interfaces.
They can be used to match or search for specific patterns or characters in a file or a string. Wildcards can also be used to create more flexible and powerful search queries, making it easier to find and manipulate the desired data.
Types of Wild Cards
Examples of common wildcard characters include the asterisk (*) and the question mark (?).
- Asterisk (*): The asterisk can be used to check for the files that match character sequences.
- Question mark (?): The question mark can be used to match any single character.
Recursively Find all Files in Current and Subfolders Based on Wildcard Matching
Finding all files in a directory and its subdirectories that match a specific pattern can be done using the “find” command in Linux. The “find” command can search files based on various criteria, such as name, permissions, type, and number of characters in file name.
To learn more about find command run the given command:
1: Finding Files Using Asterisk (*) Wildcard
To recursively find all files in the current directory and its subdirectories that match a wildcard pattern, you can use the following find command and below is the syntax for it:
The “” is a wildcard that matches any characters, so this command will find all files with names that end in “file-name”.
To find a specific directory:
To find all the directories with same name we will use a wildcard at the end of directory name:
To find all the directories and subdirectories, use wildcards at beginning and end of the directory name:
2: Finding Files Using Question mark (?) Wildcard
To find files with a specific number of characters then “?” wild card can be used, for example, if we want to find directories that contains 4 unknown characters then use:
Another way of finding recursively all files in current and subfolders based on wildcard matching in Linux pipe grep with find command:
Finding Files Using tree Command
The tree command is another useful command to find files and directories. To install tree utility use:
After installing use:
For more help about tree command, run:
Conclusion
This article covers a few examples of using the “find” command with Wildcards Question mark (?) and Asterisk (*). Using these two Wildcards we can create complex search patterns that can help you quickly locate specific files on your system. Lastly, we also cover the tree command that can find the files, folders and subfolders recursively in Linux. Using tree command a tree can be drawn for better illustration of all files inside a single directory.