Skip to content

How to delete a file whose name begin with “-” dash

Category
Tech Basics
On this page

Today, I found a file on my server named -config.ini that starts with a hyphen. It seems someone created it as a backup. The problem is, the starting hyphen is treated as a command-line option, making it tricky to delete. If you’re facing the same issue, don’t worry—this guide will show you how to remove it safely.

Files with a “-” at the beginning of their name can be removed using the rm command with additional care since the - is interpreted as an option by most Unix commands.

Delete file name begin with hyphen

Here’s how you can safely remove such files using -- to stop option parsing


rm -- -config.ini

The -- tells rm to stop interpreting anything that follows as an option, treating -config.ini as a file name.

Using Relative Path

Another way is to specify the file using its relative or absolute path:


rm ./-config.ini

This approach works because the ./ explicitly indicates the file in the current directory.

Confirm Before Deleting

If you’re not sure and want to double-check the file before deleting:


ls -- -config.ini

Conclusion

Deleting files that start with a hyphen may seem tricky at first, but it’s actually quite simple when you know the right steps. By using the methods in this guide, you can safely remove such files without any trouble. I hope this helps you solve the problem easily!

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

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


Back to top