8

I use Ubuntu 9.10 (Karmic) and I have a directory with many files, among them these two files:

./baer.jpg
./bär.jpg

I would like to delete bär.jpg but I can't.

If I type rm b and hit TAB, it shows me both files, if I append ä and hit TAB, nothing gets displayed.

What must be done in order to delete bär.jpg?

Deleting the parent folder is not a solution for me, as there are plenty of files in this directory that are used by a productive environment.

5
  • Try using midnight commander. I think you can install it with sudo apt get install mc. After that, run it with mc and us it to delete your file. Dec 27, 2012 at 8:31
  • Thanks, but I was looking for a command-line solution.
    – bzero
    Dec 27, 2012 at 8:36
  • I thought so, that's why I put this in comments :) Dec 27, 2012 at 8:41
  • 1
    Techmically you could rename baer.jpg, remove bar.jpg and rename baer.jpg back ;-)
    – Rinzwind
    Mar 20, 2014 at 9:04
  • midnight commander is command line. Do you mean coreutils?
    – Sparhawk
    Mar 26, 2014 at 13:09

3 Answers 3

13

I just found out how to delete such files witch special characters:

  1. cd <directory with that file>

  2. ls -ali

  3. At the very left of the directory listing you see the ID of the inode of each file.

  4. Delete your file via inode ID:

    find . -inum <inode ID of your file> -exec rm -i {} \;

This worked fine for my issue. Hope this helps!

1
  • +1. Very nice, if a bit convoluted. Note that -execdir is preferred (see man find). Also, another alternative would be to just run it with -delete instead, although this doesn't give you the warning of the -i flag.
    – Sparhawk
    May 28, 2014 at 5:11
3

You could use bash wildcards with

 rm b?r.jpg

where ? stands for exactly one character. An alternative (if both file names were the same length) would be

rm b[!e]r.jpg

where [!e] means any character except "e".

0

Well, you can try using matching via grep to delete the file if it's a single problematic file.

neal@dsadsa:~$ touch junk_ä_deleteme
neal@dsadsa:~$ ls | grep junk | grep deleteme | xargs rm

Here, I am creating a file named junk_ä_deleteme. I delete it afterward by matching characters before ("junk") and after ("deleteme") the funny symbol. This approach isn't very good, but if it is a single file, it might work.

Perhaps a better solution would be to form a regex to match your file, and then pipe that filename to rm.

1
  • Piping ls to grep can be unintuitive. Probably easier to just use something like find . -name 'junk*deleteme' -delete
    – Sparhawk
    May 28, 2014 at 5:14

You must log in to answer this question.

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