How to make almost all Linux files management such as finding, auto-completion, etc, case-insensitive but its shell/Bash copy and move command 'cp', 'mv' to be case-sensitive?

  • 1
    That doesn't make sense to me. Yes I could achieve it by using a shell that ignored the case (they are pretty easy to write), or picked the file you meant by ignoring case, but if you asked for file called "blah", how would it choose which file you want if your directory contained "Blah", "bLah", "blAh" or "blaH" (let alone other valid combinations). The shell would be imprecise & will lead to problems down the road because of that choice; and thus doesn't make sense. Using it would be a like installing a minefield that will result in data loss. – guiverc Nov 1 '19 at 6:22

You mentioned finding files and autocompletion as examples of where you desire case-insensitivity, but even if these are the only things that are case-insensitive--specifically, the find command and your shell's tab completion--you can get nearly all the effect of having most actions you perform from the shell be case-insensitive when you want them to be.

The reason is that there are three major situations where you enter the name of a file in a shell:

  1. The file exists and its location is known. Then you can just type its path. At some point as you do--once you've typed a unique prefix--you can press Tab. If you have reconfigured tab completion in your shell to behave case-insensitive, pressing Tab will change the case from what you've typed to that of the actual file. This works both for partial paths/filenames and for complete paths/filenames that differ by case from that of the actual file.
  2. The file exists and but its location is unknown. Then you're looking for the file. If you use find for this, you can just tell it to search case-insensitively. Usually this consists of replacing the -name test with the -iname test.
  3. The file doesn't exist yet and you intend to create it. In this situation, you have to enter the filename with whatever capitalization you want it to have, regardless of what is or is not set up to function case-sensitively. (Still, you can benefit from your shell's tab completion, in that it works for any prefixes of the path that already exist.)

Although /bin/sh in Ubuntu is provided by dash, the default user shell--the one you get when you log in non-graphically or open a terminal--is bash. Most Ubuntu users use bash. Since it's the most popular shell in Ubuntu and you've tagged this question , I'm guessing you use it. Note that the way you would make another shell (such as zsh) use case-insensitive tab completion is usually different (and some shells can't, or don't even have tab completion at all).

The way I recommend you make bash perform case-insensitive tab completion is first to try it out in a currently running shell by running the command:

bind 'set completion-ignore-case on'

After running that command, both the names of commands and the names of their filename arguments are subject to case insensitive tab completion. Although this does apply in commands like cp and mv, it only happens when you press Tab to perform the completion. Whatever text appears in a command, whether you write it or is produced by tab completion, is the text from which the arguments to the command are parsed. Therefore you always have full yet efficient control of what is and is not case-insensitive.

I don't claim this is the only or even necessarily an ideal solution, but it's a quite general and safe solution. (You might eventually want to customize tab completion further by writing custom rules for commands where you don't want it to be case insensitive.)

After you try out case-insensitive tab completion and decide you want it on all the time, you can enable it permanently--or until you decide to undo the change--by adding that same bind line to the end of your ~/.bashrc file. As init3 says you can do this either with a shell command or in a text editor:

echo "bind 'set completion-ignore-case on'" >> ~/.bashrc

Or just add the line using your favorite text editor. Restart your bash session and enjoy.

(That's from init3's answer to Can I make Tab auto-completion case-insensitive in Bash? That question shows some other ways to enable case-insensitive tab completion in bash, if you're interested.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.