Zhanhailiang Date: 2014-11-18
When using some tools, Linux often generates some files that start with a special character, such as-starting with a normal RM, which prompts "invalid option":
[Root@~]# RM-\,trail\:-Rm:invalid option-- ', 'Try`RM./-,trail:-' To remove the file '-,trail:-'. Try`RM --help' For more information.
This is because the Linux shell defaults to the-o|–option representation of the option configuration and cannot read the corresponding option configuration in the current command RM, so an error is given.
By rm–help you can see:
To remove afileWhose name starts with a`-' For example '-foo ', use one of these commands:RM -- -fooRM./-foo
In summary, to remove special files, you can use either an absolute path or a relative path or – to avoid mistakenly parsing the file name to the option configuration , which provides a variety of operational scenarios:
The first type:rm–filename
[ root@ ~" # RM---\,trail\:- rm:remove regular empty file " -,trail:-< span class= "St_ H "style=" Color:rgb (255,0,0) ">"?
second type: rm relative path
[ root@ ~" # rm./-\,trail\:- rm:remove Regular empty file " . /-,trail:-< span class=" St_h "style=" Color:rgb (255,0,0) ">"?
third type: RM absolute Path
[ root@ ~" # rm ~/-\,trail\:- rm:remove Regular empty file "/ root/-,trail:-< span class= "St_h" style= "Color:rgb (255,0,0)" > "?
A bit more in-depth analysis of source code:
First, download the source package:
[root@~/software] # wget http://down1.chinaunix.net/distfiles/coreutils-8.4.tar.gz
View SRC/RM.C Source code:
It is visible that RM directly complains when the parameter starts with a special character-and is not in the option configuration.
How Linux removes files that start with special characters