While most Linux commands are powerful on their own, some command-line tools might seem insignificant individually but become incredibly useful in conjunction with others. One such command is yes. This tutorial will guide you through its utility with clear examples.
Note: All examples in this guide were tested on Ubuntu 16.04 LTS.
Understanding the Linux Yes Command
The yes command in Linux repeats a string continuously until terminated. Here’s the command’s syntax:
yes [STRING]... yes OPTION
According to the man page:
Repeatedly output a line with all specified STRING(s), or ‘y’.
Let’s delve into some examples to better understand its usage.
Q1. How does the Yes Command Work?
The yes command produces continuous output. By default, it outputs ‘y’, but you can specify any string. Below is a demonstration:
The screenshot captures the ending of the output due to its high frequency, illustrating the command’s behavior.
You can specify a custom string as follows:
yes HTF
Q2. How Does the Yes Command Benefit Users?
While its function may seem trivial, the yes command can save time and automate repetitive tasks. Consider this scenario:
Here, the user inputs ‘y’ for each confirmation. With yes, you can automate these inputs:
yes | rm -ri test
This saves effort in scenarios requiring repeated confirmations. Another useful instance is automating ‘fsck’ command prompts, eliminating manual confirmations.
Q3. Can Yes Be Useful on Its Own?
Yes, it can stress-test a computer’s capacity to handle heavy loads. It maximizes CPU usage on single-processor systems, and for multi-processor systems, you can run multiple instances of yes.
Q4. What Command-Line Options Does Yes Offer?
The command provides generic options: –help and –version. –help displays usage information, while –version shows the command’s version.
Conclusion
The yes command is deceivingly simple yet powerful in specific scenarios. Although it lacks unique command-line options, its straightforward functionality makes it an easy tool to master. Explore more through its man page.
Frequently Asked Questions (FAQ)
What is the primary purpose of the yes command?
The primary purpose of the yes command is to repeatedly output a specified string or ‘y’ by default, which can be handy for automating responses in scripts.
Can the yes command be used for performance testing?
Yes, it can be utilized to test how well a system handles high loads by fully engaging the CPU.
Is the yes command available on all Linux distributions?
Yes, the command is included in the GNU Core Utilities, making it available on most Linux distributions.