bash 如何删除名为“?”的文件 在 linux 中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19922538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 08:35:50  来源:igfitidea点击:

how to remove a file named "?" in linux?

linuxbashcommand

提问by Yang

I created a file named "?", is anybody know how to delete it?

我创建了一个名为“?”的文件,有人知道如何删除它吗?

It seems that ? is a special character in linux, I use Redhat as my OS.

看起来 ?是 linux 中的一个特殊字符,我使用 Redhat 作为我的操作系统。

I have already tried

我已经试过了

    rm ?
    rm "?"
    rm \?

They all failed and I got the error indicated that the file doesn't exist.

他们都失败了,我收到错误指示该文件不存在。

回答by slayedbylucifer

find the inode of the file:

找到文件的inode:

ls -li

then delete the file using inode:

然后使用inode删除文件:

find . -inum <inode-number> -exec rm -i {} \;

BTW, rm ?works for me fine. here is my bash version:

顺便说一句,rm ?对我来说很好。这是我的 bash 版本:

# bash --version
GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)

回答by rici

rm \?and rm "?"are both perfectly good ways to delete a file named ?. If they didn't work, and you still seem to have a file name ?, then it is most likely that the ?being shown is not really a ?, but rather the result of substituting an unprintable character with a ?. To see what the file is really called (with GNU ls) try:

rm \?并且rm "?"都是删除名为?. 如果它们不起作用,并且您似乎仍然有一个文件名?,那么?显示的很可能不是真正的 a ?,而是用?. 要查看文件的真正名称(使用 GNU ls),请尝试:

ls --quoting-style=escape

回答by anubhava

Use this rmcommand to remove a file named ?:

使用此rm命令删除名为 的文件?

rm ./\?

OR from another directory:

或从另一个目录:

rm /path/to/\?

回答by alacerda

You can delete the file by its inodenumber. see the output bellow:

您可以通过其inode号删除文件。看下面的输出:

alplab:~/cad# ls -il
63051 -rw-r--r--    1 root     root             0 Nov 12 11:48 ?
alplab:~/cad# find . -inum 63051 -exec rm -i {} \;

I used the "find" command to delete the file with the inode number 63051(the inode belonging to my "?" file).

我使用“find”命令删除了 inode 编号为63051的文件(属于我的“?”文件的 inode)。