Find All Files with Extension in Linux

31

Often, we find ourselves stuck when we have to find all files with the same or different extensions. This has most likely happened to various Linux users while using the terminal. It is one thing to search for a single file type or file, but what will you do when you want to find out all files simultaneously? This article comes to the rescue for our readers who have such a dilemma.

We can use various Linux utilities for finding or locating files on a file system, but searching all files or filenames with the same or different extensions can be difficult and require specific patterns or expressions. In the upcoming section of the article, we will understand the working, syntax, and execution of these utilities.

Find command

One of the most powerful file searching tools in the Linux system is the “find command.” It searches the entire directory for files and folders to get matched with the user’s expression and performs actions on these files. File permission, file size, type are some other factors based on finding files on Linux. Find command also be combined with other utilities such as sed or grep. Now, lets’ head towards the practical implication of find command.

Find command syntax:

$ find Directory Options Expression

Finding all files with a single extension:

To find all files with a file extension, write out its path to find a command with the options and expression specifying the extension. In the below-given example, we will find all files with the “.txt” extension.

$ find . -type f -name “*.txt”

“.” in this command denotes that this tool will find all the “.txt” files in the current directory.

find all files with extension in linux Find All Files with Extension in Linux 1622095890 655 Find All Files with Extension in Linux

find all files with extension in linux Find All Files with Extension in Linux 1622095890 15 Find All Files with Extension in Linux

Find “.exe” files in the same find command by adding the extension as “*exe.”

$ find . -type f -name “*.exe”

find all files with extension in linux Find All Files with Extension in Linux 1622095891 89 Find All Files with Extension in Linux

find all files with extension in linux Find All Files with Extension in Linux 1622095891 674 Find All Files with Extension in Linux

find all files with extension in linux Find All Files with Extension in Linux 1622095892 374 Find All Files with Extension in Linux

Configuration files are also an essential part of any file system that can be used for multiple purposes. Write out this command for searching configuration files in the current directory.

$ find /etc -type f -name “*.conf”

find all files with extension in linux Find All Files with Extension in Linux 1622095893 756 Find All Files with Extension in Linux


find all files with extension in linux Find All Files with Extension in Linux 1622095893 720 Find All Files with Extension in Linux
find all files with extension in linux Find All Files with Extension in Linux 1622095894 814 Find All Files with Extension in Linux
Finding files with multiple extension:

You can also add more than extension in your find command so that you can find several extension files easily and quickly.

The execution of below given command will retrieve files with extension “.sh” and “.txt”

$ find . -type f ( -name “*.sh” -o -name “*.txt” )

find all files with extension in linux Find All Files with Extension in Linux 1622095894 847 Find All Files with Extension in Linux

find all files with extension in linux Find All Files with Extension in Linux 1622095895 894 Find All Files with Extension in Linux

find all files with extension in linux Find All Files with Extension in Linux 1622095896 542 Find All Files with Extension in Linux

Locate command

The locate command is a faster and better tool as compared with “find.” When a file is initiated, instead of searching it in the file system, locate utilize the database for the searching requirement. This database stores parts and bits of the information related to files and their addresses on your system.

locate command syntax:

Finding a file with a specific extension, such as “.conf,” which is considered in our case, adds the directory path where the process of searching files will occur.

find all files with extension in linux Find All Files with Extension in Linux 1622095896 250 Find All Files with Extension in Linux

find all files with extension in linux Find All Files with Extension in Linux 1622095897 412 Find All Files with Extension in Linux

Find configuration files in the present working directory by utilizing the below-given command.

find all files with extension in linux Find All Files with Extension in Linux 1622095897 444 Find All Files with Extension in Linux

find all files with extension in linux Find All Files with Extension in Linux 1622095898 376 Find All Files with Extension in Linux

find all files with extension in linux Find All Files with Extension in Linux 1622095898 909 Find All Files with Extension in Linux

Similarly, you can follow the syntax of locate command for finding all files with any specific extension such as “.txt.”

find all files with extension in linux Find All Files with Extension in Linux 1622095899 275 Find All Files with Extension in Linux

find all files with extension in linux Find All Files with Extension in Linux 1622095900 437 Find All Files with Extension in Linux

Conclusion:

This post covers two powerful yet simple utilities for you to find all files with the same or different extensions. We have provided you the fundamental concepts regarding the “find” and “locate” command and shown you how to utilize these two Linux command-line tools to find all files with several extensions.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More