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.
2 Answers
"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.
The Wikipedia article has a good explanation.
Basically it spams a "yes" to wherever it is run. This can be used to automate responses to programs that ask for user verification. As an example, the following:
rm -f *.txt
is functionally equivalent to
yes | rm *.txt
It pipes the "yes" to rm
, so to any question that rm
asks (write protection or similar), it will immediately get a "yes" and continue.
Common programs like apt
or rm
have a "force" function built in, but other programs may not. This is where yes
can be useful.
It can also be used as input to create a certain size of file, or to stress test a system.