如何删除打开终端时出现的 "grep: XXX: Is a directory" 日志?

How can I remove "grep: XXX: Is a directory" logs appearing when terminal is opened?

如何删除打开终端时出现的 grep: XXX: Is a directory 日志?

为什么总是出现这些日志?

Last login: Fri Jan 28 14:44:36 on ttys005
grep: Applications: Is a directory
grep: Desktop: Is a directory
grep: Documents: Is a directory
grep: Downloads: Is a directory
grep: Library: Is a directory
grep: Movies: Is a directory
grep: Music: Is a directory
grep: Pictures: Is a directory
grep: Postman: Is a directory
grep: Public: Is a directory
grep: Sites: Is a directory
grep: test: Is a directory
grep: work: Is a directory

~
❯ 

Linux 手册页提到有一个 -d 选项,可以指定一些操作,如跳过等。

https://man7.org/linux/man-pages/man1/grep.1.html

-d ACTION, --directories=ACTION

If an input file is a directory, use ACTION to process it. By default, ACTION is read, i.e., read directories just as if they were ordinary files. If ACTION is skip, silently skip directories. If ACTION is recurse, read all files under each directory, recursively, following symbolic links only if they are on the command line. This is equivalent to the -r option.

grep命令用于检查文本文件中的匹配。

如果您在 grep 命令文件列表中包含目录,则会出现这些错误。

如果您想省略 grep 文本文件中的目录,请使用以下选项:--directories=skip

如果您想从 grep 个文本文件递归目录,请使用以下选项:--directories=recurse

grep 命令帮助中所述。

  -d, --directories=ACTION  how to handle directories;
                            ACTION is 'read', 'recurse', or 'skip' 

您的启动文件之一,例如 .zprofile 正在调用 grep foo * 或类似文件。您需要找到并删除该行或将其更改为 grep -d 是否有用。有关要查看的 zsh 启动文件列表,请参阅 https://zsh.sourceforge.io/Guide/zshguide02.html 中的第 2.2 节。