bash 命令“rm *~”的作用是什么?做?

发布于 2024-10-09 18:10:55 字数 168 浏览 7 评论 0原文

bash 命令 rm *~ 是否只是删除以波形符结尾的文件,或者这里是否有更高级的 bash 或 gnu make 模式?谷歌似乎无法搜索这两个符号的组合。我在 Makefile clean: 目标中找到了这个。

gnu make 是否会仅使用隐式规则创建带有尾随 ~ 的文件?

Does the bash command rm *~ just remove files ending in tilde or is there a more advanced bash or gnu make pattern here? Google does not seem able to search for this two symbol combination. I found this in a Makefile clean: target.

Would gnu make ever create files with trailing ~'s using only the implicit rules?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

怀里藏娇 2024-10-16 18:10:55

在两种情况下,~(波形符)字符在路径中具有特殊含义:

~user        # the home directory of user
~/folder     # folder inside your home directory

在大多数情况下,就是这样。您引用的命令的作用与它看起来的完全一样:删除名称以波形符结尾的文件。 emacs 等文本编辑器以波浪号结尾的文件名保存文件的备份副本。

因此,此命令可能用于从当前目录(但不是子目录)中删除这些备份副本。人们想要这样做的原因之一是该目录是否将被复制到 Web 服务器,因为服务器端代码(例如 PHP 文件)可能包含密码等敏感信息。

The ~ (tilde) character has a special meaning in a path in two cases:

~user        # the home directory of user
~/folder     # folder inside your home directory

For the most part, that's it. The command you refer to does exactly what it looks like it does: removes files whose names end in a tilde. Text editors such as emacs save backup copies of files under filenames ending in tildes.

So, this command is probably used to remove these backup copies from the current directory (but not subdirectories). One reason why one would want to do so is if the directory will be copied to a web server, as server-side code (e.g. PHP files) can contain sensitive information such as passwords.

风情万种。 2024-10-16 18:10:55

正如您所猜测的,rm *~ 只是删除名称以波形符 (~) 结尾的文件。以波形符结尾的文件名通常是编辑器创建的备份文件(特别是,emacs 是最早使用此约定的编辑器之一)。编辑源代码后,通常会留下许多这样的文件。这就是 Makefile 中的 clean 目标删除这些内容的原因。

*~ 是否是某种特殊的 bash 模式与大多数 makefile 无关,因为默认情况下使用 /bin/sh 来执行 make 配方。仅当在 makefile 中设置了 SHELL 时才会使用不同的 shell。

查看 make 隐式规则的一个简单方法是在没有 makefile 的目录中运行 make -p 。您将收到一条错误消息,指出未指定目标,但 make 还将打印出它正在使用的隐式规则。如果您对此输出进行 grep 查找波浪号,您将看到没有隐式规则用它来命名文件。

As you guessed, rm *~ just removes file with names ending with a tilde (~). Filenames ending with a tilde are usually backup files created by editors (in particular, emacs was one of the earlier editors to use this convention). After editing source code, it is common to have a number of these files left behind. This is why the clean target in the Makefile removes these.

Whether *~ is some special bash pattern is not relevant for most makefiles, as /bin/sh is used by default to execute make recipes. Only if SHELL is set in the makefile will a different shell be used.

An easy way to see make's implicit rules is to run make -p in a directory without a makefile. You will get an error saying no targets specified, but make will also print out the implicit rules it is using. If you grep this output for a tilde, you'll see there are no implicit rules that name files with it.

梦中的蝴蝶 2024-10-16 18:10:55

不,就是你说的那样。删除以 ~ 结尾的文件。

编辑-> ~ 字符可能具有的唯一特殊含义是当前用户主目录的简写(如 $HOME),但仅出现在路径的开头。

Nope, just what you said. Removes files ending with ~.

Edit -> the only special meaning the ~ character may have, is as short-hand for the the current user's home directory (as $HOME), but only in the beginning of a path.

━╋う一瞬間旳綻放 2024-10-16 18:10:55

我已经使用该命令删除以“~”结尾的文件。我认为没有与波形符相关的特殊转义字符。

I have used that command to erase files ending in "~". I think that there is no special escape character associated with the tilde symbol.

吹梦到西洲 2024-10-16 18:10:55

是的


实际上,你的两种可能性都有些正确。

没有与 ~ 关联的通配符或特殊文件名语法,除非它出现在单词的开头。

但以波形符结尾的文件名模式是由大多数 Linux 发行版上的 mv(1)cp(1) 程序自动生成的 1 如果指定了-b(备份)选项并且目标文件存在。此类系统上的 make 规则可能包含 mv -b ...cp -b ... 命令。


1.但不适用于 Mac 或 BSD。

Yes to both


Actually, both of your possibilities are somewhat true.

There is no wildcard or special filename syntax associated with ~, unless it occurs at the beginning of a word.

But the filename pattern ending in tilde is produced automatically by the mv(1) and cp(1) programs on most linux distros1 if the -b (backup) option is specified and the target file exists. A make rule on such a system might contain a mv -b ... or cp -b ... command.


1. But not on the Mac or BSD.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文