How to access files starting by minus in the shell

Files starting by minus can be difficult to be managed by the shell, since the minus symbol is usually used by the options of the executed command. So, to specify a file in the current directory, you cannot write the name of the file as it is. Moreover, for some mysterious reason, also if the file name is quoted the problem persists.

The solution to this problem is really simple: Put a “./” before the file name.

For example, the command to delete the file “-afilename” from the current directory will be the following.

$ rm ./-afilename

This post is also available in Italian: Link.

3 thoughts on “How to access files starting by minus in the shell”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.