Unix / Linux: Delete File with Special Characters

Objective: Delete a file with names that contain spaces and/or special characters such as hyphen (-), semicolon (;), ampersand (&), dollar sign ($), question mark (?), asterisk (∗), etc.

Let’s look at the files that we want to delete below.

Now, let’s look at how we can delete those files.

Delete File with Quotes

For file name with spaces, using quotes will help.

Delete File with Backslash

You can insert a backslash (\) before a space or special character in the filename.

Delete File by Adding ./

If you try deleting a file with a hyphen in front, you will get an error.

Instead, try adding ./ to the filename.

Delete File by Adding --

To delete a file with hyphen, you can also use the following syntax.

Delete File with Inode Number

To get the inode number of a file, use ls with -i option. The first column contains the inode number.

Use the find command to delete the file using the inode number.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }