Unveiling the Hidden Gem: The ‘yes’ Command

**Unveiling the Hidden Gem: The ‘yes’ Command**

In the vast realm of Linux commands, there’s a little-known gem that often goes unnoticed: ‘yes’. Despite its unassuming name, this command packs a surprising punch and can be a lifesaver in various situations.

**What is ‘yes’?**

‘yes’ is a simple yet powerful command that continuously outputs a specified string. By default, it prints “y”. However, you can customize the output using the ‘-s’ option.



**Common Options:**

* **-s STRING:** Specifies the string to output.
* **-n NUM:** Specifies the number of times to repeat the string.
* **-i:** Prompts the user for confirmation before each output.

**Example Uses:**

**1. Piping ‘yes’ to Other Commands:**

‘yes’ can be piped to other commands as input. For instance, to create a file named ‘test.txt’ with a specific string, you can use:

yes “Sample text” | tee test.txt

**2. Automatic Input for Interactive Programs:**

When running interactive programs that require user input, you can use ‘yes’ to automate the process. For example, to automatically install a software package using ‘apt-get’, you can type:

yes | apt-get install software_name

**3. Continuous Output for Testing Purposes:**

‘yes’ can generate a continuous stream of data for testing purposes. This is helpful for testing network connections, file transfers, and other operations that involve continuous input or output.

yes | nc -u -w 1 localhost 80

**4. Password Entry Automation:**

If you need to enter a password multiple times, you can use ‘yes’ to automate the process. For example, to enter the password “secret” three times, you can type:

yes secret | command_requiring_password

**5. Infinite Looping:**

By default, ‘yes’ runs indefinitely. To create an infinite loop, you can simply type:



The ‘yes’ command may seem simple at first glance, but it’s a versatile tool that can save you time and effort in various situations. Whether you need to automate input, generate continuous data, or create infinite loops, ‘yes’ has you covered. So next time you encounter a task that requires repetitive input, don’t hesitate to use this hidden gem in your Linux toolkit.