如何删除以“>”或其他不寻常字符开头的文件


8

我不小心创建了一个名为

> option[value='2016']

如何删除?

My attempts:

$ rm "> option[value='2016']"
rm: cannot remove ‘> option[value='2016']’: No such file or directory
$ rm \> o*
rm: cannot remove ‘>’: No such file or directory
rm: cannot remove ‘o*’: No such file or directory
$ rm `> o*`                                                                               
rm: missing operand
Try 'rm --help' for more information.
$ rm \> option*
rm: cannot remove ‘>’: No such file or directory
rm: cannot remove ‘option*’: No such file or directory
$ rm '\> option*'                                                                         
rm: cannot remove ‘\\> option*’: No such file or directory
$
$ rm "\> option*"                                                                         
rm: cannot remove ‘\\> option*’: No such file or directory

文件清单:

HAPPY_PLUS_OPTIONS/
o*
op*
> option[value='2016']
> option[value='ALFA ROMEO']
README.md
rspec_conversions/
.rubocop.yml
SAD/
SAD_PLUS_OPTIONS/

您是否尝试过使用通配符?rm * option *
RageAgainstTheMachine

以下问题看起来很荒谬,但是您尝试使用GUI文件管理器吗?
Incnis Mrsi 2015年

Answers:


16

另外一个选项

ls -i 

给出(具有适当的inode值)

5233 > option[value='2016']   5689 foo

然后

find . -inum 5233 -delete

optionnaly(预览)

find . -inum 5233 -print

-xdev如果下面还有另一个文件系统,也可以添加。


9

您还可以根据个人使用“-”选项:

 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

所以我尝试了:

touch -- "> option[value='2016']"

并使用以下命令将其删除:

rm -- "> option[value='2016']"

检查文件名是否正确输入的最简单方法:

rm -- ">[tab]

然后让自动完成功能完成这项工作。

PS:听起来很诱人,请不要创建文件名“ -rf *”。坏事可能发生。

-rw-r--r--    1 stephan  staff      0 Sep 13 14:11 -rf *

为了安全起见,请始终使用“ -i”。

iMac:~ stephan$ rm -i -- "-rf *"
remove -rf *? Y

到目前为止,这是最好的答案。

8

最初的问题是领导空间,因此

rm " > option[value='2016']"
    ^ here

作品。

将问题更新为关于以>等开头的文件。


3

对于交互式方法(通常更安全):

当前目录中是否有一些特殊的命名文件。

您可以使用rm ./然后TabTab列出文件,然后选择文件并将其删除。


输入Tab两次以查找文件。
Shellmode

1

因为rm,没有什么神奇的>。您只需要确保尖括号就可以到达(=防止外壳将其解释为重定向)。

> "> option[value='2016']"  #create it
rm "> option[value='2016']" #remove it

#remove all files in the current directory that have > in them
rm -- {,.}*\>*                 

如果您使用的是明智的现代系统,则应该能够使用制表符补全来正确地转义名称。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.