kac*_*442 8 filesystem command-line rm
“ls -l”的输出:
-rw-r--r-- 1 root root 0 Mar 4 08:22 -t
Run Code Online (Sandbox Code Playgroud)
当我尝试执行“rm '-t'”时:
rm: invalid option -- 't'
Try 'rm ./-t' to remove the file '-t'.
Try 'rm --help' for more information.
Run Code Online (Sandbox Code Playgroud)
Way*_*Yux 24
您可以使用rm -- -t
或rm ./-t
从 man rm
To remove a file whose name starts with a '-', for example '-foo',
use one of these commands:
rm -- -foo
rm ./-foo
Run Code Online (Sandbox Code Playgroud)
您也可以使用find
:
find . -maxdepth 1 -type f -name '-t' -delete
Run Code Online (Sandbox Code Playgroud)
例子:
% ls
egg -t
% find . -maxdepth 1 -type f -name '-t' -delete
% ls
egg
Run Code Online (Sandbox Code Playgroud)