Rm delete the file or directory at the beginning of the dash

  
                  

rm deleting (clearing) one or more files -f option will force the file to be deleted, even if the file is read-only and can be used to avoid user input (used in non-interactive scripts). The directory after the file whose name starts with a special symbol, such as .mk @, can be deleted directly by rm -rf, or by adding the escaping character & rdquo;\\”

I encountered this situation today ……

rm will not be able to delete files starting with a dash.

rm -slow_query_130103.txt.gz

rm: invalid option -- s

Try `rm ./-slow_query_130103.txt.gz' to remove the file `-slow_query_130103.txt.gz'.

Try `rm -- Help' for more information.

Officially made a special note in the help documentation:

To remove a file whose name starts with a `-', for example `-foo', use one Of these commands: rm -- -foo

rm ./-foo

One way to solve this problem is to add "./" to the front of the file to be deleted.

# rm ./-slow_query_130103.txt.gz

rm: remove regular file `./-slow_query_130103.txt.gz'?

Another solution Add " -- ". in front of the file name.

# rm -- -slow_query_130102.txt.gz

rm: remove regular file `-slow_query_130102.txt.gz' ?

Copyright © Windows knowledge All Rights Reserved