I have a problem when trying removing a file with name something like -h_some_file_name
, this is because of generated script that I made and forget to check the prefix.
If I run the command rm '-h_some_file_name'
it return an error rm: invalid option -- 'h'
.
If I try to change the name and then remove it using mv '-h_some_file_name' new_filename
it return mv: invalid option -- 'h'
Question:
How to remove a file with name like -h_some_file_name
in shell? if using gui I can right click and move to trash, but in shell only returns an error
Just:
Or:
See the manpage of
rm
:The
--
argument tellsrm
that all following argument should not be treated as parameters. A variety of other Linux/Unix command line tools support that argument. This interpretation of--
follows the POSIX argument parsing conventions1). Themv
utility also supports it:1) The Open Group Base Specifications Issue 7, IEEE Std 1003.1, Guideline 10
You can use wildcards. Here in this case you can use '*' wildcard.
Go to the directory where files of this type is to be deleted or you need to mention the complete path in the command.
After setting to the terminal prompt to your directory, type in the following
For little bit more information you can see this link: http://tldp.org/LDP/GNU-Linux-Tools-Summary/html/x11655.htm
For indepth information follow some book related to bash.