How to ignore case sensitive in ls
The ls
command is one of the most frequently used commands in Linux. It is used to list the contents of a directory. However, by default, the ls
command is case-sensitive, which means it differentiates between uppercase and lowercase characters. This can be a problem when you want to search for a file or directory that has a mixed case name. In this blog post, we will discuss how to let ls
command ignore case sensitive characters.
ls
Command
If you want to ignore case sensitive characters with the ls
command, you can use the -i
option. This option tells the ls
command to ignore the case of the characters in the file names. To use this option, simply type ls -i
in the terminal.
ls -i
This will list all the files and directories in the current directory, ignoring the case of the characters in their names.
ls
Command with grep
You can also use the ls
command with grep
to ignore case sensitive characters. The grep
command is used to search for a specific pattern in a file. By default, the grep
command is case-sensitive, but you can use the -i
option to ignore case sensitive characters.
To use the ls
command with grep
, you need to pipe the output of ls
to grep
. Here is an example:
ls | grep -i "filename"
This command will list all the files and directories in the current directory that contain the pattern “filename”, ignoring the case of the characters in their names.
shopt
### switch off case sensitive mode
shopt -s nocaseglob
### switch on case sensitive mode (default)
shopt -u nocaseglob
### help shopt
help shopt
zsh unsetopt
### switch on case sensitive mode
unsetopt CASE_GLOB
### switch off case sensitive mode (default)
setopt CASE_GLOB