Skip to content

Linux yes command

The Linux yes command is a simple utility that outputs a string or character specified as an argument, repeatedly. It is often used in scripts for automation, as well as for generating a continuous stream of a specific input. The yes command can be helpful in various scenarios, such as confirming prompts in batch scripts or providing continuous input for testing purposes. It is a straightforward tool that can be useful in a variety of scripting and automation tasks.

yes Syntax:

Terminal window
yes [string]

Options:

OptionDescription
-h, —helpDisplay help information
-V, —versionDisplay version information

Parameters:

ParameterDescription
stringThe string to be repeated infinitely

yes Usage:

Repeat “hello world” indefinitely

Terminal window
yes "hello world"

Repeats the phrase “hello world” indefinitely in the terminal.

Generate a sequence of numbers

Terminal window
yes | nl

Generates a sequence of numbers in the terminal, starting from 1 and increasing indefinitely.

Overwrite a file with a specific pattern

Terminal window
yes "pattern" > file.txt

Overwrites the file “file.txt” with the specified pattern, replacing its contents.

Simulate keyboard input for a command

Terminal window
yes | command

Simulates pressing the Enter key (newline) repeatedly, useful for automating interactive commands.

How do I use yes in Linux?

To use the yes command in Linux, execute the following command:

Terminal window
yes

What is the purpose of the yes command in Linux?

The yes command in Linux is used to repeatedly output a line or string specified by the user.

How can I generate a specific string using the yes command in Linux?

To generate a specific string with the yes command in Linux, provide the string as an argument like this:

Terminal window
yes "Hello, World!"

How do I redirect the output of the yes command to a file in Linux?

To redirect the output of the yes command to a file in Linux, you can use the ”>” symbol like this:

Terminal window
yes "Hello, World!" > output.txt

Can I use the yes command in a loop or script in Linux?

Yes, you can use the yes command within a loop or script in Linux to automate tasks or simulate user input.

Is there a way to stop the yes command output in Linux?

You can stop the output of the yes command by using the “head” command to limit the number of lines generated, like this:

Terminal window
yes | head -n 10

Applications of the yes command

  • Automating repetitive data input
  • Stress testing programs by generating a large amount of output
  • Simulating user input for scripts and commands
  • Testing how a program reacts to continuous positive input
  • Providing constant input for piping to other commands