The Linux yes command allows you to automate responses to scripts and commands, but how it responds is up to you. Credit: sarawuth702 / Getty Images One of the more unusual Linux commands is named “yes”. It’s a very simple tool intended to help you avoid having to answer a lot of questions that might be asked when you run a script or a program that needs a series of responses to do its work. If you type “yes” by itself at the command prompt, your screen is going to start filling up with the just the letter “y” (one per line) until you hit control-C to stop it. It’s also incredibly fast. Unlike what you see displayed below, yes will likely spit out more than a million y’s in the time it likely takes you to reach down and press control-C. Fortunately, that’s not all that this command can do. $ yes y y y ^C If you like, you can pipe the output of the yes command to the head command to see a small sample of its output. $ yes | head -3 y y y Once the command receiving the output ends, the yes command ends as well. If you want to fill up your screen with “no”, some other word, or even a complete sentence, you can do that. The command “yes no” will repeatedly display “no” until you terminate the command, again with a control-C. $ yes no | head -3 no no no You could even use a command like “yes I am filling up my screen” and watch your screen filling up with “I am filling up my screen”. There is one thing that you shouldn’t even consider doing with yes. Here goes: WARNING: One thing you really shouldn’t do is redirect the output of the yes command to a file. It will grow a lot faster than you will likely expect. So, what is yes meant to do? Since we’ve covered what yes can do, let’s look at how it’s meant to be used. The yes command was built to send answers to scripts or binaries when you prefer not to have to answer their questions yourself. In fact, the yes command makes it easy to run commands non-interactively and is often used to automate processes that will run overnight. The limitation is that whenever you use the yes command, every line of output is going to be the same – whether “y” (the default), “yes” or something else. There is no way that you can get yes to answer “yes” to one question and “no” to another. If you were using a script like the one shown below that asks a series of questions and you want the yes command to answer them for you, you could pipe the output of yes to the script using a command like this: $ yes | myscript The script would read the “y” answers provided by the yes command and respond accordingly. $ yes | askme Ready to answer some questions? [y,n] Did you work more than 8 hours today? [y,n] Then you may need some rest! Are you ready for a nap? [y,n] Get some nice rest! Alternately, you could ask yes to answer all questions with an “n”: $ yes no | askme Ready to answer some questions? [y,n] OK, good bye! The script: #!/bin/bash echo "Ready to answer some questions? [y,n]" read ans if [ "$ans" != "y" ]; then echo "OK, good bye!" exit fi echo "Did you work more than 8 hours today? [y,n]" read ans case $ans in y) echo "Then you may need some rest!";; n) echo "OK, but you can take a short break";; *) echo "Avoiding the question?" esac echo "Are you ready for a nap? [y,n]" read ans case $ans in y) echo "Get some nice rest!"; exit;; n) echo "OK. Get some good work done!";; *) echo "Too difficult a question?";; esac Wrap-up The yes command is limited to repeating the same response to every question asked by a script or command, but it provides a way to run commands without having to be present to provide the needed responses. Related content how-to How to examine files on Linux Linux provides very useful options for viewing file attributes, such as owners and permissions, as well as file content. By Sandra Henry Stocker Oct 24, 2024 6 mins Linux how-to 8 easy ways to reuse commands on Linux Typing the same command again and again can become tiresome. Here are a number of ways you can make repeating commands – or repeating commands but with some changes – a lot easier than you might expect. By Sandra Henry-Stocker Oct 15, 2024 5 mins Linux news SUSE Edge upgrade targets Kubernetes and Linux at the edge SUSE Edge 3.1 includes a new stack validation framework and an image builder tool that are aimed at improving the scalability and manageability of complex Kubernetes and Linux edge-computing deployments. By Sean Michael Kerner Oct 15, 2024 6 mins Edge Computing Linux Network Management Software how-to Lesser-known xargs command is a versatile time saver Boost your Linux command line options and simplify your work with xargs, a handy tool for a number of data manipulation tasks. By Sandra Henry Stocker Oct 11, 2024 6 mins Linux PODCASTS VIDEOS RESOURCES EVENTS NEWSLETTERS Newsletter Promo Module Test Description for newsletter promo module. Please enter a valid email address Subscribe