2

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
  • 1
    I wouldn't remove anything in linux starting with /
    – Braiam
    Commented Oct 4, 2013 at 14:40

1 Answer 1

11

Bad solution:

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

Better:

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.

4
  • Careful though won't this remove all in the subdirectories?
    – CoderDake
    Commented Oct 3, 2013 at 17:41
  • 3
    Try -maxdepth 1. Thanks for remind, answer edited
    – aso
    Commented Oct 3, 2013 at 17:50
  • @user2843739 - I'll be very thankful for check my answer as best :)
    – aso
    Commented Oct 3, 2013 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
    Commented Oct 4, 2013 at 15:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .