ISO27001:2013
Certified Supplier

FIND OUT MORE

We're an ISO27001:2013 Certified Supplier

blog-post-featured-image

Files with special characters in them can cause no end of problems. Here’s two ways to deal with them.

Consider the following file:

$ ls -l
-rw-r--r-- 1 jmw jmw 0 May 30 15:01 --my-unfortunate-file

Using rm in the usual way will give an error, although it also gives a hint as to how the file may be removed:

rm --my-unfortunate-filename
rm: unrecognized option '--my-unfortunate-filename'
Try 'rm ./--my-unfortunate-filename' to remove the file ‘--my-unfortunate-filename’.

Preceding the filename with ./ works in this case, but there are other cases where that may not be so easy. Here we have a filename containing Unicode characters:

$ ls -l
-rw-r--r-- 1 kae kae 0 May 31 16:29 €½

If you’re not easily able to generate Unicode characters from your keyboard (or you can’t remember how to), removing this file may be challenging, but there is another way.

We can manipulate the file using its inode number. Every file in the filesystem has an inode, which is the link between the file’s entry in the directory and the data blocks which hold its contents. Every inode has a unique number within the filesystem.

ls has an option, -i,  to display the file’s inode number

$ ls -i
130508 €½

Now we can use the find command to remove the file:

$ find . -inum 130508 -delete
$ ls -l
total 0

Could this Linux Tip be improved?

Let us know in the comments below.

Leave a Reply

Your email address will not be published. Required fields are marked *