How to use the touch command to create a file with an arbitrary filename.

Posted: June 28, 2014. At: 6:24 PM. This was 4 years ago. Post ID: 7469
Page permalink.
WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters. These cookies expire two weeks after they are set.

The touch command ordinarily does not allow the user to create files with a filename like –rf, but if you want to really annoy someone then you may use this command to create one.

[email protected]:~$ touch -- '--rf '

And now you have a file named –rf.

-rw-r--r--  1 homer homer    0 Jun 28 16:26 -rf

This file cannot be easily deleted, the –rf is interpreted by rm as a command parameter.

Therefore, this trick is necessary to delete this file.

[email protected]:~/test$ rm -- -rf

The -- parameter to rm signifies the end of command line parameters to the rm command. This allows you to delete this file. Below is another example.

homer@debian:~/test$ ls -hula
total 24K
-rw-r--r--  1 homer homer    0 Jun 28 16:26 --
drwxr-xr-x  2 homer homer 4.0K Jun 28 18:07 .
drwxr-xr-x 24 homer homer 4.0K Jun 28 17:59 ..
-rw-r--r--  1 homer homer  10K Jun 28 16:21 archive.tar
-rw-r--r--  1 homer homer    0 Jun 28 16:17 --checkpoint=1
-rw-r--r--  1 homer homer    0 Jun 28 16:17 --checkpoint-action=exec=sh 
-rw-r--r--  1 homer homer    0 Jun 28 16:26 -f
-rw-r--r--  1 homer homer    0 Jun 28 18:07 --rf 
-rwsr-sr-x  1 homer homer   26 Jun 28 16:21 shell.sh

Use this command to delete this file.

[email protected]:~/test$ rm -- --rf

This is very easy, you cannot create a file named . though. But give this a try yourself and see how you go!

No comments have been made. Use this form to start the conversation :)

Leave a Reply