Tags

, , , ,

Some badly formatted command may lead to a filename with a leading dash in its name, e.g. -bad_file. To delete this file in the command line either of the following commands should be enough:

$ rm -- -bad_file

OR

$ rm ./-bad_file

But if the filename is just a dash (-), things may get a little tricky. Follow the steps 1–3 to delete a file named as “ – ”:

[you may use this method to delete the first file, -bad_file as well]

1. Find the inode numbers first. The following command will print the file serial number (inode number)  for each file in the working directory:

$ ls -li

2. Then check to see if the inode number (say, 12345) of the culprit, viz. “  – ”,   corresponds to it correctly (optional step):

$ find . -inum 12345

3. If it finds the name of the `culprit’ correctly, which it should if the number is correct, proceed  to remove it:

$ find . -inum 12345 -exec rm {} \;

That’s it!

Credit: here.

Advertisements