removing the file -X

I have created a file named in my home folder named -x (just for curiocity that can it be deleted or not)
oops .... its problematic the file is not deleting now.</p>

and then I Learned about ,

rm -- -x

-- means ignore any further options.
Usefule for lots of commands, not just rm

# Try the regular rm command and enclose your troublesome filename in quotes. This may solve the problem of deleting files with spaces in their name, for example:  rm "File Name"

You can also remove some other characters in this manner, for example:
rm "filename;#"

The quotes prevent the semicolon from being interpreted as a stacking command. (Since you can string commands together in Unix with semicolons, Unix will interpret a semicolon in a filename that way, unless you put it in quotes.)
# You can also try renaming the problem file, using quotes around your original filename, by entering: mv "filename;#" new_filename

If this command successfully renames the file, you can then use the rm command to delete the file using the new name.
# If this doesn't work, insert a backslash ( \ ) before the meta-character in your filename. The backslash causes the character that follows to be interpreted literally. For example, to remove the file named my$project, enter: rm my\$project
# To remove a file whose name begins with a dash ( - ) character, refer to the file with the following syntax: rm ./-filename

Using the redundant  ./  directory information prevents the dash from occurring at the beginning of the filename, and being interpreted as an option of the rm command.</div>

comments powered by Disqus