The yes command

Today I learned about this weird command yes. It prints the letter “y” or a specified string1 indefinitely until you stop it (with Ctrl+C)…

$ yes
y
y
y
...

or

$ yes "Hello world"
Hello world
Hello world
Hello world
...

My first thought was “why the heck would anyone need it?”. Well, below are the most common uses according to ChatGPT:

  1. Automating prompts: Many CLI tools ask “Are you sure? [y/N]”. Piping yes sends endless y\n responses:

    yes | apt-get install package
    

    Saves time in batch scripts.

  2. Stress-testing I/O: yes can generate data as fast as your CPU can handle, great for testing write speed:

    yes > /dev/null
    
  3. Generating large files: Redirect its output to create huge test files quickly:

    yes "test line" > bigfile.txt
    

I guess these days it’s mostly useless, but it was handy back in the day.


  1. It can even say “no” if you ask nicely :) ↩︎