如何删除名称以“--”开头的文件?
How to delete file whose name begins with "--"?
我不小心创建了一个名为“--address=16.187.249.27
”的文件,尝试用以下方法删除它,但没有成功:
$ rm "--address=16.187.249.27"
rm: unrecognized option '--address=16.187.249.27'
Try 'rm ./'--address=16.187.249.27'' to remove the file ‘--address=16.187.249.27’.
Try 'rm --help' for more information.
$ rm "\--address=16.187.249.27"
rm: cannot remove ‘\--address=16.187.249.27’: No such file or directory
如何删除名称以“--”开头的文件?
将 --
的单个实例添加到命令行意味着后面的所有内容都是文件名而不是标志参数。所以应该这样做:
rm -- --address=16.187.249.27
来自手册页
NOTE
The rm command uses getopt(3) to parse its arguments, which allows it to accept the --
option which will cause it to stop
processing flag options at that point. This will allow the removal of
file names that begin with a dash (`-').
For example:
rm -- -filename
The same behavior can be obtained by using an absolute or relative path reference.
For example:
rm /home/user/-filename
rm ./-filename
所以你可以通过运行
删除
rm -- --address=16.187.249.27
有多个选项可以删除这样的文件:
rm ./--address\=16.187.249.27
rm "./--address=16.187.249.27"
rm './--address=16.187.249.27'
rm -- --address=16.187.249.27
find -maxdepth 1 -name "--address=16.187.249.27" -delete
我不小心创建了一个名为“--address=16.187.249.27
”的文件,尝试用以下方法删除它,但没有成功:
$ rm "--address=16.187.249.27"
rm: unrecognized option '--address=16.187.249.27'
Try 'rm ./'--address=16.187.249.27'' to remove the file ‘--address=16.187.249.27’.
Try 'rm --help' for more information.
$ rm "\--address=16.187.249.27"
rm: cannot remove ‘\--address=16.187.249.27’: No such file or directory
如何删除名称以“--”开头的文件?
将 --
的单个实例添加到命令行意味着后面的所有内容都是文件名而不是标志参数。所以应该这样做:
rm -- --address=16.187.249.27
来自手册页
NOTE The rm command uses getopt(3) to parse its arguments, which allows it to accept the
--
option which will cause it to stop processing flag options at that point. This will allow the removal of file names that begin with a dash (`-').For example: rm -- -filename
The same behavior can be obtained by using an absolute or relative path reference.
For example: rm /home/user/-filename rm ./-filename
所以你可以通过运行
删除rm -- --address=16.187.249.27
有多个选项可以删除这样的文件:
rm ./--address\=16.187.249.27
rm "./--address=16.187.249.27"
rm './--address=16.187.249.27'
rm -- --address=16.187.249.27
find -maxdepth 1 -name "--address=16.187.249.27" -delete