Introduction
In the world of system administration and scripting, it is often necessary to generate a steady stream of text to feed other commands, test applications, or quickly fill files. The Linux yes command does exactly that: it produces an unlimited output of a specified string (by default, the letter «y») until it is interrupted.
What is the yes command?
Originating from early Unix systems, yes is a simple utility that belongs to the coreutils package. Its sole purpose is to repeatedly write a string to standard output, followed by a newline, until it receives a termination signal (such as Ctrl+C) or its output is redirected to another process that closes it.
Basic syntax
The simplest form is:
yes [string]
If [string] is omitted, the command assumes «y» and produces an endless column of y followed by \n. For example:
yes
Will produce:
y
y
y
…
Practical examples
- Automatically respond to prompts: Many programs ask if you want to continue (
y/n). Redirecting the output ofyesto their standard input allows automating the response:yes | apt-get updateThis assumes that all questions will be answered with «y».
- Generate test files: If you need a large file filled with a pattern, combine
yeswithheadordd:yes 'Linux' | head -n 10000 > prueba.txtYou will get 10 000 lines with the word Linux.
- Test server resilience: In load testing, you can use
yesto produce simple data traffic:yes | nc -v example.com 80This will send a continuous stream of «y» to port 80, useful for checking how the server handles persistent connections.
Useful options
Although yes is minimalist, GNU coreutils includes some options that can be useful:
--help: displays the standard help.--version: displays the command version.
There are no options to change the delimiter or suppress the newline; if you need output without a newline, you can combine it with tr -d '\n' or use printf in a loop.
Precautions and best practices
- Avoid infinite loops in production: Letting
yesrun uncontrolled can consume CPU and fill disks if its output is redirected to a file. Always limit the amount withhead,sedor atimeout. - Combine it with
timeout: To ensure the command does not run indefinitely, use:timeout 30s yes 'prueba' > salida.txtThis will stop
yesafter 30 seconds. - Be careful with interactive prompts: Always forcing «y» can be dangerous if the program expects a different response to abort destructive operations. Check the command’s documentation before automating responses.
Conclusion
The yes command may seem trivial, but its ability to generate repetitive and endless text streams makes it a valuable tool for administrators, developers, and testers. From automating responses during installations to creating massive test files, understanding how it works and its limitations will allow you to use yes safely and efficiently in any Linux environment.
This post is also available in ESPAÑOL.