How to delete '!' file on Linux (exclamation mark symbol)

I guess by accident we created a file called ‘!’ (exclamation mark). See it is how it looks on Ubuntu server:

-rw-r--r-- 1 root root  641 Oct 23 05:16 '!'
drwxr-xr-x 2 root root 4096 Oct 23 05:33  bin
-rw-r--r-- 1 root root 1007 Jul  2 19:00  commands.txt
-rw-r--r-- 1 root root 5059 Jun 25 19:45  com.conf
-rw-r--r-- 1 root root 2429 Jun 23 18:05  old.conf
drwxr-xr-x 4 root root 4096 Jun  3 11:17  snap
drwxr-xr-x 2 root root 4096 Jun 25 18:55  updated

So how can delete the ! safely on Linux?

The ! symbol must be quoted to prevent history expansion. It has many other usage under bash. Hence, Try any one of the following command-line syntax to delete and remove file named with special symbols in it:

rm -v -i ./\! 

OR

rm -i -v -- '/path/to/!'

You will see message as follows:

rm: remove regular empty file '/path/to/!'?

Where rm options are as follows:

  • -i : prompt before every removal
  • -v : verbose output

See the following tutorial for more info:


And:

Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki