← 返回命令列表

Linux command

yes 命令

文本

涉及管道、覆盖或删除,执行前请先确认路径和参数。

常用示例

Output 'y' repeatedly

yes | [command]

Output a custom string repeatedly

yes "[custom text]"

Auto-answer 'no' to all prompts

yes n | [command]

Output for a limited number of lines

yes | head -n [10]

说明

yes outputs a string repeatedly until killed or the pipe closes. By default, it outputs "y" followed by a newline, endlessly. The primary use is piping to commands that ask for confirmation, automatically answering "y" (or any specified response) to all prompts. This is useful for scripting commands that don't have native batch/quiet modes. When the receiving command closes its stdin (by exiting), yes terminates automatically due to the broken pipe. Without piping, yes runs indefinitely and must be interrupted with Ctrl+C.

参数

--help
Display help and exit.
--version
Display version and exit.

FAQ

What is the yes command used for?

yes outputs a string repeatedly until killed or the pipe closes. By default, it outputs "y" followed by a newline, endlessly. The primary use is piping to commands that ask for confirmation, automatically answering "y" (or any specified response) to all prompts. This is useful for scripting commands that don't have native batch/quiet modes. When the receiving command closes its stdin (by exiting), yes terminates automatically due to the broken pipe. Without piping, yes runs indefinitely and must be interrupted with Ctrl+C.

How do I run a basic yes example?

Run `yes | [command]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --help do in yes?

Display help and exit.