Find A File While Ignoring Case Sensitivity

Today we’ll have a fairly short article as we’re simply discussing a way to find a file while ignoring case sensitivity. This can be a pretty handy command to have in your toolbox, so I’ll do what I can to turn this into an article. If you’re into finding files, especially with the terminal, you might just want to read this article!

I might even give you a bonus method! Maybe… It depends on how well you behave yourself! Don’t make me pull this car over!

Alright… Back on topic…

So, what is case sensitivity? We usually have lowercase files and commands. Linux is case-sensitive. If you type sudo APT update nothing is going to happen. Why? Because apt is lowercase. Similarly, a file named  FOO.bar is not the same as foo.bar.

If you try to perform an operation on a file with the wrong case, the operation will not take place. The file isn’t found, because you’ve used the wrong case. In the above command, not even SUDO apt update will work. You have to use lowercase.

Much of Linux is in lowercase. You can’t even use capital letters in your username, by default. Sure, you can force Linux to accept a bad username, but that’s not what the system is expecting.

So too are filenames. Well, mostly… Sometimes you will come across files that use mixed case or maybe all capital letters. You might even have created a file yourself with mixed case letters. When performing an operation on those files, you need to use the correct case.

Now, you can find files while ignoring the case. That’s what this article is all about accomplishing. It shouldn’t be too long.

The Find Command:

The find command is used in the terminal, so we will have to open the terminal to follow along with today’s article. However, on the plus side, you absolutely shouldn’t need to install anything. This find command should be available by default – unless you’re on an extremely stripped-down version of Linux.

If you check the man page, you’ll see that find is the right application for this.

find – search for files in a directory hierarchy

As we’re trying to find files (while ignoring case sensitivity) that seems like one of the good tools for the job – and it is.

Find A File While Ignoring Case Sensitivity:

As mentioned above, we do this in the terminal. More often than not, you can just press CTRL + ALT + T and your default terminal should open. Otherwise, you can open your terminal via your application menu.

With your terminal now open, let’s change directories and create a file.

You can confirm that the file exists by running the ls command.

Next, try this command:

Unless you have another file with that name, you will not get any results from that command. That’s why you need the -iname flag. Simply add that to your command and you can find the file while ignoring case sensitivity.

So, in our case, it’d be:

Sure enough, that finds HeLLo.txt.

If you don’t feel like changing the directory, you can change the command up a bit. The syntax would look like this:

So, in our example:

And, sure enough, that finds the file while ignoring case sensitivity! 

Pretty neat and pretty easy, right?

How about that bonus?

Find A File While Ignoring Case Sensitivity (with locate):

You probably don’t have locate installed by default. You’ll need to install it.

To that end, read this previous article:

And Still Another Way To Find Files By Extension

Specifically this part is of interest (saving you a click):

With your terminal open, we can get mlocate installed with one of the following commands:

Debian/Ubuntu:

Arch/Manjaro/etc:

RHEL/CentOS/etc:

OpenSUSE/GeckoLinux/etc:

There are other package managers. If your package manager isn’t covered, just go ahead and search for “mlocate” and you’ll likely find that it’s available by default.

So, with locate now installed, the syntax is also very simple. You simply need the -i flag to find files while ignoring case sensitivity.

First, we should update the locate database:

Next, try this command:

That will not find the file in your ~/Documents directory. Add the flag and run the command again, like so:

If you want to run that locate command in a specific directory, you can do that. The syntax is a little different than many other commands, but it’s easy enough.

Or, in our case, it’d look like this:

Sure enough, that outputs the information exactly as planned. It will happily ignore the case sensitivity and find your file named HeLLo.txt.

And now you’ve learned two ways to find a file while ignoring case sensitivity. One of the ways is even a nice bonus way to do accomplish this goal.

Closure:

As the headline and opening paragraph suggested, you can find a file while ignoring case sensitivity. It’s not particularly taxing and there are multiple ways to accomplish this goal. I figured I’d give some ‘bonus’ information with this one and share how to find a file while ignoring case sensitivity with the locate command used in the previous article. Why not?

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Last Updated on November 8, 2023 by KGIII

Subscribe to Newsletter!
Get notified when new articles are published!
We promise to never share your email!
icon

Author: KGIII

Retired mathematician, residing in the mountains of Maine. I may be old and wise, but I am not infallible. Please point out any errors. And, as always, thanks again for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.