How to delete a file in linux with spaces

If you create a file in Linux with special character like %,$, * etc then you cannot remove it simply with rm command. In order to delete this kind of file, you need to use the inode number of this file. In this tutorial, I will try to show you that how we can delete the file in Linux that contains the special character and spaces in it’s name.

First, we will create a file with special character as well as spaces in it’s name:

touch "$this is %a +bad -example"

Let’s check the created file and it’s ownership information:

ls -l

From the ownership information, it is clear that I have rights to delete this file, now we try to delete this file:

rm is %a +bad -example

Note: You can if you add the before the name, but you’d have to guess as a user that it was used in the file creation.

To delete this file, we need to know it’s inode number by using this command:

ls -il

Then use the find command to delete the file by it’s inode:

find . -inum 270016 -exec rm -i {} ;

Hope this will help you!