The File Type Hunt
When cleaning up a Linux server or searching through massive directories of downloaded code, you rarely know the exact names of the files you are looking for. Instead, you usually know the type of file. For example, you may need to locate every single Python script (.py), every massive archive file (.tar.gz), or every single image (.png) scattered across hundreds of deeply nested sub-directories. To isolate files strictly by their file type, you must instruct the Linux search engine to evaluate the characters at the very end of the file name.
Using the find Command with Wildcards
The Linux find command utilizes the standard -name flag combined with the wildcard asterisk (*) to match specific file extensions.
- Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
- To scan the entire
/home/user/directory and return every single text file (ending in .txt), type the following command exactly: find /home/user/ -type f -name "*.txt"- Press Enter.
Wildcard Protection
The quotation marks around the search string ("*.txt") are absolutely critical. The asterisk acts as a wildcard, meaning “match any number of characters, as long as it ends in .txt.” If you do not wrap the string in quotes, the Bash shell itself will attempt to expand the asterisk before handing the command to find, which will instantly break the search engine if there are multiple text files in your current directory. Always wrap wildcard extension searches in quotes.