Bash: deleting a file with special characters using its inode value

If you have a file with special characters (single quotes, wildcard, etc) in the name, it can be difficult to discover the exact escape sequence to correctly delete.  To avoid playing with escape characters, you can simply use the inode number of the file instead.

For example, let’s say you accidentally specify tar options incorrectly and create a file with special characters.

# purposely incorrect order of exclude flag !!!!!
$ tar cvfz --exclude=*.zip my-archive.tgz *.txt

# do listing by with inode in first column 
# uh-oh we created a file with special chars in the name
$ ls -latri
...
835558 -rw-rw-r-- 1 fabian fabian 45 Nov 8 09:52 '--exclude=*.zip'

# delete by inode number
$ find . -inum 835558 -delete

By the way, the ‘c’ (create) flag means the archive name must immediately follow, which means the ‘exclude’ flag MUST be ordered like below if you are trying to correctly call tar.

tar cvfz my-archive.tgz --exclude=*.zip *.txt

REFERENCES

Vivek Gite, inode value and removal