I am a new Unix shell user at my university shell server. Accidentally, I had created a file called -foo. Now, how do I remove a file with a name starting with ‘-‘ under UNIX-like or Linux operating system?
You can use standard UNIX/Linux rm command. All you have to do is instruct the rm command not to follow end of command line flags by passing double dash -- option before -foo file name.
Many user creates these kind of file accidentally with dashes. If you attempt to remove such file via rm command, UNIX and Linux will attempt to use them as command-line options and the command will display out with an error. So how do you get rid of these files and delete them on a UNIX?
rm command syntax
Use rm command to remove files or directories as follows:
rm -- -foo
Other options: Unix remove file with dash
Some more options remove the —- Dashes —- on a Unix-like system:
rm ./-Foo rm "./---bar" rm -- -F rm -- ---footbal ## Edit file ## vi "./--foo"
rm — -F
rm — —footbal
## Edit file ##