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 find files on Linux There are many options you can use to find files on Linux, including searching by file name (or partial name), age, owner, group, size, type and inode number. By Sandra Henry Stocker Jun 24, 2024 8 mins Linux opinion Linux in your car: Red Hat’s milestone collaboration with exida With contributions from Red Hat and critical collaborators, the safety and security of automotive vehicles has reached a new level of reliability. By Sandra Henry Stocker Jun 17, 2024 5 mins Linux how-to How to print from the Linux command line: double-sided, landscape and more There's a lot more to printing from the Linux command line than the lp command. Check out some of the many available options. By Sandra Henry Stocker Jun 11, 2024 6 mins Linux how-to Converting between uppercase and lowercase on the Linux command line Converting text between uppercase and lowercase can be very tedious, especially when you want to avoid inadvertent misspellings. Fortunately, Linux provides a handful of commands that can make the job very easy. By Sandra Henry Stocker Jun 07, 2024 5 mins Linux PODCASTS VIDEOS RESOURCES EVENTS NEWSLETTERS Newsletter Promo Module Test Description for newsletter promo module. Please enter a valid email address Subscribe