Home Linux Commands How to Find Files Ignoring Case Sensitivity in Linux

How to Find Files Ignoring Case Sensitivity in Linux

Being a Linux user, have you faced trouble in finding a specific file because its name had different letter cases? As Linux is super picky about case sensitivity while searching for files, and it can be really frustrating when you can’t remember the exact letter case or word arrangement used in the filename.

But fear not! This guide will offer a collection of nifty commands that will enable you to locate your desired files effortlessly, without being bogged down by case sensitivity.

1. Using Find Command

The find command is a powerful utility available in most Linux distributions, which is designed to search for files and directories within a specified directory and its subdirectories based on various criteria.

To find files while ignoring case sensitivity using the find command, you can use the -iname option, which allows you to perform a case-insensitive search for files based on their names.

$ find /path/to/search -iname "filename"

For example, you want to find all files named “ubuntumint.txt” in the “/home/ubuntumint” directory and its subdirectories, irrespective of their letter case.

$ find /home/ubuntumint -iname "ubuntumint.txt"
Find Files by Ignoring Case Sensitivity
Find Files by Ignoring Case Sensitivity

The above command will list all files named “ubuntumint.txt“, “Ubuntumint.txt“, “UBUNTUMINT.txt“, and so on, in the specified directory and its subdirectories.

Here is the breakdown of the above syntax:

  • /path/to/search – Specifies the starting directory for the search.
  • -iname: The flag responsible for the case-insensitive file search.
  • filename: Name of the file you are looking for.

Moving forward, we can also utilize the find command with wildcard characters to search for the filename even if you don’t remember the complete name of the file.

$ find /home/ubuntumint -iname "ubunt*.txt"
Find Files by Wildcard
Find Files by Wildcard

2. Using Find and Grep Commands

Now that you understand how powerful the find command is, it’s time to explore its combination with the grep command to perform a case-insensitive file search using the '-i' flag which serves the same purpose as the “-iname”.

The syntax for finding a file using the find and grep combination is provided below:

$ find /home/ubuntumint/ | grep -i "ubuntumint.txt"
Search Files by Ignoring Case Sensitivity
Search Files by Ignoring Case Sensitivity

In this syntax, the find command will search for all files and provide them as input to the grep command, which will then locate the file disregarding the letter case.

3. Using ls and Grep Commands

In this method, we will search files from the current working directory without taking care of the case sensitivity of the file name with the help of the ls command in combination with the “grep -i” command.

We can search for multiple files having the same extension in the current directory by executing this command:

$ ls | grep -i ".txt"
Find Files by Extension
Find Files by Extension

You can see the power of the “-i” flag, how it wonderfully enables a case-insensitive file search, providing the correct result.

4. Using Locate Command

Last but not least, let’s discuss another amazing Linux utility called “locate” which looks for files and directories by utilizing the pre-built database of filenames and paths.

The locate command is installed in most Linux distributions by default, however, if it’s not installed, you can install it using your package manager as shown.

$ sudo apt install mlocate         [On Debian, Ubuntu and Mint]
$ sudo zypper install mlocate      [On OpenSUSE] 
$ sudo yum install mlocate         [On RHEL/CentOS/Fedora and Rocky/AlmaLinux]
$ sudo apk add mlocate             [On Alpine Linux]
$ sudo pacman -S mlocate           [On Arch Linux]
$ sudo emerge -a sys-apps/mlocate  [On Gentoo Linux]

Then, after installing locate utility, execute the “sudo updatedb” command to update the file database, which will be utilized by locate.

$ sudo updatedb

Lastly, let’s try to find a configuration file using the locate command.

$ locate -i ubuntumint.txt
Locate Files by Ignoring Case Sensitivity
Locate Files by Ignoring Case Sensitivity

That’s it for now! you can look for your desired file without getting hung up on letter case sensitivity. Happy file searching!

Conclusion

These methods provide you with different ways to search for files while ignoring case sensitivity on your Linux system. Choose the one that suits your preferences and needs best, and simplify your file search process.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.