首页 > 解决方案 > 为什么命令行 rm 不接受带有空格的目录的引号?

问题描述

由于空格和括号,在 Debian 命令行中运行rm projects/artwork/My Project (543893)/Images/*.png不起作用。我需要逃离他们。但我认为引号 "" 是转义的替代方法。它适用于其他命令,例如cd,但不适用于rm. 这是为什么?

标签: linuxquotingrm

解决方案


因为 globbing 不适用于引用:

$ ll /tmp/"d i r"/*.png
-rw-r--r--. 1 postgres postgres 0 May 26 14:02 /tmp/d i r/a.png
-rw-r--r--. 1 postgres postgres 0 May 26 14:02 /tmp/d i r/p.png
$ ll "/tmp/d i r/*.png"
ls: cannot access /tmp/d i r/*.png: No such file or directory
$ rm "/tmp/d i r/*.png"
rm: cannot remove ‘/tmp/d i r/*.png’: No such file or directory
$ rm /tmp/"d i r"/*.png
$ ll /tmp/"d i r"/*.png
ls: cannot access /tmp/d i r/*.png: No such file or directory

推荐阅读