Home > Environment & Utility > yes

yes: Repeat strings indefinitely

The yes command repeatedly outputs a specified string (defaulting to 'y') on a new line. It is primarily used in scripts to automatically provide a 'y' or other response to user confirmation prompts. It continues to run until interrupted by pressing Ctrl+C.

Overview

`yes` is a simple utility that continuously outputs a specific string in an infinite loop. It is mainly used to automatically respond to confirmation questions when interactive commands are executed automatically, making it useful for script automation.

Key Features

  • Repeatedly outputs the default string 'y'
  • Can repeat a user-specified string
  • Useful for automatically responding to confirmation prompts of other commands
  • Can be stopped by pressing Ctrl+C

Main Options

By default, the `yes` command outputs 'y'. However, you can provide an argument to make it repeat a different string. There are no separate flag options.

Specify String to Repeat

Generated command:

Try combining the commands.

Description:

`yes` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Examples demonstrating various ways to use the `yes` command. It is often used in conjunction with other commands via pipes (|).

Default 'y' Repetition

yes

Continuously outputs 'y' until Ctrl+C is pressed.

Repeat a Specific String

yes "Hello World!"

Repeatedly outputs the string 'Hello World!'.

Automatic Response to Confirmation Prompts

yes | rm -i my_file.txt

Automatically answers all confirmation prompts for interactive commands (e.g., `rm -i`) with 'y' to proceed with deletion. **Caution: This command can be very dangerous and should be used with extreme care.**

Using with xargs

find . -name "*.txt" -print0 | yes | xargs -0 rm -i

When executing `rm -i` for all .txt files found by the `find` command, `yes` automatically approves the deletion confirmation. **This is a very dangerous combination and requires caution.**

Tips & Precautions

The `yes` command is very simple, but it can be powerfully utilized when combined with other commands. However, it must be used with caution.

How to Stop the Command

The yes command runs indefinitely, so you must forcefully stop it by pressing Ctrl+C in the terminal.

  • Ctrl+C: Terminates the currently running yes process.

Caution with Automation

When using the yes command to automatically respond to interactive prompts, extreme caution is advised. Especially when used with commands that modify or delete data such as rm, mv, or cp, it can lead to unintended data loss. Always ensure you fully understand the command and test it before executing automated scripts.

Alternatives

In certain situations, you might consider alternatives to yes.

  • Some commands offer their own automatic confirmation options, such as -y or --assume-yes. If available, using these options is generally safer.
  • Instead of simulating user input with conditional logic within a script, you can implement it to perform operations only when necessary.


Same category commands