Linux – Using find command to find folder ignoring case

findlinux

I would like to know if a particular folder is present or not. I used the following command

find /mnt/md0/ -maxdepth 1 -name 'dcn'||'DCN'

I want to know if folder name is DCN or dcn .
How would I do this ?

Best Answer

You're looking for the option -iname, which stands for "ignore case" on GNU find along with the option -type d for selecting only directories.

find /mnt/md0/ -type d -maxdepth 1 -iname dcn

For more a detail explanation on find switches you consult explainshells.com's explanation of find. (This will match any case: dcn , DcN, DCn)

Edit 1:

As state in comment by Olivier Dulac to use with non GNU find or old find version you could use :

find /mnt/md0 -type d -maxdepth 1 -print | grep -i '/dcn$'

see this answer to have a real compatibility with non GNU and old find version

Related Question