Is there is a way to remove a file or directory ignoring if the name of the file is uppercase or lowercase?

Example. I both /FiLe and /file.

If I write: rm /file will it remove these two?

  • 1
    I wouldn't remove anything in linux starting with /
    – Braiam
    Oct 4 '13 at 14:40

Bad solution:

rm [Ff][Ii][Ll][Ee]


find . -iname "file" -exec rm {} \;

From man:

-iname pattern
       Like  -name, but the match is case insensitive.

Also, limit depth to only current directory; add -maxdepth 1 before iname:

find . -maxdepth 1 -iname "file" -exec rm {} \;

Hope that helps.

  • Careful though won't this remove all in the subdirectories? Oct 3 '13 at 17:41
  • 3
    Try -maxdepth 1. Thanks for remind, answer edited
    – aso
    Oct 3 '13 at 17:50
  • @user2843739 - I'll be very thankful for check my answer as best :)
    – aso
    Oct 3 '13 at 18:31
  • If you use -exec rm {} then this will for a whole new process (rm) for each file. You can use -exec rm {} + instead which will feed rm as many pathnames as possible for each invocation of utility. And there is always the option to use the build-in -delete.
    – Hennes
    Oct 4 '13 at 15:20

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.