Ubuntu – An example of when we need yes command

command line

What is the usage of yes command. I follow the man yes also I try that but I want to know when we need to use this command. You can follow man page to know the usage of yes. But I am looking for a time when we need that? In which situation I need example.

Best Answer

"yes" was created to allow automation of tasks that request confirmation. If you have a program that wants you to tell it "y" before it does something, you can now automate that program by piping yes into it.

Example :

yes | rm -i *.txt

Here yes is piped for confirmation to delete all txt files in the directory .

Another option print a string repeatedly :

yes "test"

Stop by Ctrl + C

It also can be used to say no , this repeat n after the rm :

yes n | rm -i *.txt

The above example says not to remove a file when rm -i prompts to remove the file.

Related Question