How to be repetitively affirmative: the Unix way

May 28th, 2018 | #terminal

TIL how to be repetitively affirmative: the Unix way.

By accident I discovered the yes command today. It outputs 'y', forever. Why? Well, quite a simple reason actually. You can use it as a quick way to provide answers to an interactive script. For example for rm.

Usually rm asks you about any file being removed. You could supply -f to rm, so you are not bothered with questions. However, using yes also works:

yes | rm -r huge_directory

The man page for yes:

$ man yes

YES(1)                    BSD General Commands Manual                   YES(1)

     yes -- be repetitively affirmative

     yes [expletive]

     yes outputs expletive, or, by default, ``y'', forever.

     The yes command appeared in 4.0BSD.

4th Berkeley Distribution        June 6, 1993        4th Berkeley Distribution

© 2018 Tonny Garić | With from Nijmegen, The Netherlands