This article provides a comprehensive guide to the ‘yes’ command in Linux, detailing its history, usage, and how it works in conjunction with other commands for scripting and automation tasks. Despite its simplicity, the ‘yes’ command is a versatile tool for both new and experienced users, demonstrating the Unix philosophy of small, simple tools that perform one thing well, but can be combined to perform complex tasks.
Introduction
This article serves as a comprehensive guide to understanding and using the yes
command in Linux. Designed with beginners in mind, it offers a detailed walk-through of the command, starting from its history and usage, to its various parameters, common use cases, and even some tricky skills. By the end of this guide, you'll be well-equipped to harness the full power of the yes
command in your Linux journey.
History
The yes
command is a part of the GNU core utilities package that is included in all Unix-based systems. Introduced in Unix Version 7 in the late 1970s, it is one of the simple but versatile commands that form the core building blocks of Unix and Unix-like systems such as Linux.
When and why to use it
The yes
command is used to output a string repeatedly until killed. This command might seem redundant at first, but it is quite handy in scripting and automation tasks, where an unattended operation needs to interact with a command that expects user input. The yes
command can provide the necessary input (usually 'y' or 'n') automatically, making it a very useful tool in many situations.
How to use it
Using the yes
command is straightforward. By default, without any arguments, it outputs 'y' indefinitely until stopped.
$ yes
y
y
y
...
To stop the command, you can simply use the Ctrl + C combination. If you want to print a different string, you can provide it as an argument to the yes
command.
$ yes "This is a test"
This is a test
This is a test
This is a test
...
When and why to use it
The yes
command is used to output a string repeatedly until killed. This command might seem redundant at first, but it is quite handy in scripting and automation tasks, where an unattended operation needs to interact with a command that expects user input. The yes
command can provide the necessary input (usually 'y' or 'n') automatically, making it a very useful tool in many situations.
How to use it
Using the yes
command is straightforward. By default, without any arguments, it outputs 'y' indefinitely until stopped.
$ yes
y
y
y
...
To stop the command, you can simply use the Ctrl + C combination. If you want to print a different string, you can provide it as an argument to the yes
command.
$ yes "This is a test"
This is a test
This is a test
This is a test
...
The tricky skills
The yes
command itself is simple and straightforward, but it can be used creatively in combination with other commands or scripts for some unusual usage techniques. For example, you can use the yes
command to generate a large file quickly for testing purposes.
$ yes "This is a test" > testfile.txt
The above command will create a file named ‘testfile.txt’ and keep filling it with the line “This is a test” until the filesystem is full or the command is manually stopped.
What needs to be noted
It is important to note that the yes
command will run indefinitely until it is interrupted or the program it is piped into terminates. So, you should be careful while using it, especially when redirecting its output to a file, as it can quickly fill up your disk space.
Conclusion
The yes
command in Linux, while simple in its operation, is a handy tool for scripting and automation. Despite not having specific parameters, its ability to provide continuous 'yes' or any string as input can be quite useful in many situations. Its simplicity and ease of use make it a powerful and versatile command in the hands of both new and experienced users. The yes
command is a great example of the philosophy behind Unix-like operating systems – small, simple tools that do one thing well, but can be combined in interesting ways to perform complex tasks.