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.
- Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
- To search the entire
/var/www/web directory for every single JPEG image, type the following command exactly: sudo find /var/www/ -type f -name "*.jpg"- 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).