When I do ls
in my directory, get bunch of these:
data.log".2015-01-22"
data.log".2015-01-23"
However when I do this:
rm: cannot remove `data.log.2015-01-22': No such file or directory
If I could somehow do something line ls | escape quotes | xargs rm
So yeah, how do I remove these files containing "
?
Update
While most answer work. I was actually trying to do this:
ls | rm
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 -- *
and answer y
or n
as appropriate. This can be used to get rid of many files having funny characters in their name.
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.
Use single quotes to quote the double quotes, or backslash:
rm data.log'"'*
rm data.log\"*
Otherwise, double quotes are interpreted by the shell and removed from the string.
Don't process the output of ls
. Filenames can contain spaces, newlines, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With