如何删除文件名中带引号的文件 [英] how to delete a file with quote in file name

查看:86
本文介绍了如何删除文件名中带引号的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在目录中执行 ls 时,得到一堆这样的东西:

When I do ls in my directory, get bunch of these:

data.log".2015-01-22"
data.log".2015-01-23"

但是,当我这样做时:

rm: cannot remove `data.log.2015-01-22': No such file or directory

如果我能以某种方式在行 ls |转义报价|xargs rm

If I could somehow do something line ls | escape quotes | xargs rm

是的,我如何删除这些包含" 的文件?

So yeah, how do I remove these files containing "?

更新

大多数答案都能奏效.我实际上是在尝试这样做:

While most answer work. I was actually trying to do this:

ls | rm

因此某些文件失败.如何在 ls 之后在管道中转义引号?实际上,大多数答案都是针对文件的手动操作.但是我问的是 ls 之后的转义/替换引号.抱歉,我的问题令人困惑.

So it was failing for some files. How can I escape a quote in a pipe after ls? Most of the answers actually addresses the manual manipulation of file which works. But I was asking about the escaping/replacing quotes after the ls. Sorry if my question was confusing.

推荐答案

如果您只需要偶尔互动一次,请使用

If you only need to do this once in a while interactively, use

rm -i -- *

并根据需要回答 y n .这可以用来删除许多文件名中包含有趣字符的文件.

and answer y or n as appropriate. This can be used to get rid of many files having funny characters in their name.

它的优点是不需要键入/转义有趣的字符,空格等,因为使用 * 的shell会为您做到这一点.它也很短,很容易记住.

It has the advantage of not needing to type/escape funny characters, blanks, etc, since the shell globbing with * does that for you. It is also as short as it gets, so easy to memorize.

这篇关于如何删除文件名中带引号的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆