How to Find Files by Extension in Ubuntu Linux

The File Type Filter

In Ubuntu Linux, files do not strictly require an extension to function (a text file can simply be named “Document” rather than “Document.txt”). However, almost all standard media files and web documents still use extensions to help users identify them. If you are trying to organize a chaotic downloads folder or audit a web server for unauthorized media uploads, searching for files by name is useless. Instead, you must instruct the Linux kernel to search the filesystem specifically for the three or four characters at the very end of the filename.

Using the find Command with Wildcards

The Linux find command utilizes the -name flag combined with the asterisk (*) wildcard character to filter by extension.

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

Understanding the Syntax

The asterisk (*) is the secret to this command. In Linux, the asterisk means “match absolutely anything.” By typing *.jpg, you are telling the search engine: “I do not care what the beginning of the filename is, as long as it ends exactly with .jpg.” You can easily modify this to find any file type:

  • find ~/Documents -name "*.pdf" (Finds all PDF documents).
  • find ~/Downloads -name "*.zip" (Finds all compressed archives).
  • find / -name "*.mp4" (Hunts down massive video files across the entire server).

Get the best tech tips delivered straight to your inbox.

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