How to Find Files by Specific Extension in Ubuntu Linux

The Extension Filter

When working on an Ubuntu Linux server, you will frequently need to locate a specific type of file scattered across multiple different folders. For example, if you are migrating a web application, you might need to find every single Javascript (.js) file or every single Python (.py) script within the project directory. Scanning thousands of files manually is impossible. Instead, you must instruct the Linux filesystem to search using a “wildcard” character combined with the specific file extension you are looking for.

Using the find Command with Wildcards

The Linux find command utilizes the -name flag along with the asterisk (*) wildcard to filter files strictly by their suffix.

  1. Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
  2. To search the entire /var/www/ directory for every single text file (.txt), type the following command exactly:
  3. sudo find /var/www/ -type f -name "*.txt"
  4. Press Enter and provide your administrator password.

Case Sensitivity

By default, the -name flag is strictly case-sensitive. The command above will find data.txt but it will completely ignore data.TXT. If you are searching for image files (where extensions like .JPG and .jpg are frequently mixed), you should swap the flag to -iname (case-insensitive name). For example: sudo find /home/user/ -type f -iname "*.jpg". This guarantees the search engine will catch every single image file regardless of how the extension is capitalized.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.