• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
The Electric Toolbox Blog

The Electric Toolbox Blog

Linux, Apache, Nginx, MySQL, Javascript and PHP articles

  • Applications
  • FCKEditor
  • Apache
  • Windows
  • Contact Us
Home / Delete a file starting with a dash/hypen on Linux on the command line

Delete a file starting with a dash/hypen on Linux on the command line

So you have a file that starts with a dash/hyphen/- and need to delete it. But when you try to do so, the "rm" command complains that you have passed an "invalid option –". This post looks at the simple solution to deleting a file that starts with a dash/hyphen.

As an example, doing a directory listing gives you something like this:

$ ls -l
total 678586
-rw-r--r-- 1 root root        54 Apr 29 15:39 -.log
-rw-r--r-- 1 root root     26819 Apr 30 13:17 210.5.53.35.log
-rw-r--r-- 1 root root     18114 Apr 30 01:37 210.5.53.36.log
-rw-r--r-- 1 root root     18410 Apr 30 01:37 210.5.53.37.log
...

You try to delete the -.log file like this:

rm -.log

and rm complains like this:

rm: invalid option -- .
Try `rm ./-.log' to remove the file `-.log'.
Try `rm --help' for more information.

The answer is actually supplied in the error message, which is fairly unusual for a Linux/Unix command. Instead of doing rm -.log you simply add ./ to the start and run this instead:

rm ./-.log

This will also work for other command line utilities you need to run against a file starting with a hypen/dash.

Check Out These Related posts:

  1. How to mount an ISO image on Linux
  2. Create a file in Linux
  3. Executing shell commands from within the MySQL command line client
  4. Sudo command

Filed Under: Linux/Unix/BSD

Primary Sidebar

Categories

  • Apache
  • Applications
  • Article
  • Case Studies
  • Email Servers
  • FCKEditor
  • HTML And CSS
  • Javascript
  • Linux/Unix/BSD
  • Microsoft SQL Server
  • Miscellaneous Postings
  • MySql
  • Networking
  • Nginx Web Server
  • Offsite Articles
  • OSX
  • PHP
  • Quick Tips
  • RFC – Request for Comments
  • SilverStripe
  • VMWare
  • VPN
  • Windows
  • WordPress

Recent Posts

  • Vim Show Line Numbers
  • Add User To Group Linux
  • Chmod 777 Tutorial
  • How to Copy Directory Linux
  • Linux create user

Copyright © 2021. ElectricToolBox. All Rights Reserved.

  • Contact Us
  • Copyright Info
  • Privacy Policy
  • Sitemap