mac os 查找没有终止符的命令

mac os find command no terminating character

在我的 git 项目中,我需要删除所有以 **.pyc 结尾的文件。因此,我 运行 下面的命令,但是得到了 no terminating ";" 这个错误,我不明白它是什么意思。

find . -name "**.pyc" -exec git rm {};
find: -exec: no terminating ";" or "+"

如果我 运行 find . -name "**.pyc" 我会得到所有 .pyc 格式文件的列表。

当你执行find . -name "**.pyc" -exec git rm {};时,shell读取;作为终止字符并执行命令find . -name "**.pyc" -exec git rm {}。但这是一个错误,因为 find 期望 -exec 命令被 ; 终止。也就是说,您需要将 ; 作为参数之一传递给 find。您可以通过使用 find . -name "**.pyc" -exec git rm {} \;find . -name "**.pyc" -exec git rm {} ";" 将其转义为 shell 来完成此操作 另一种选择是使用 + 终止 -exec,这将调用 git rm 有一个以上的参数,导致对 git 的调用更少。这样稍微方便一些,因为 + 不需要转义。