News for hackers. Stuff that matters.
Re:How is GNU `yes` so fast? by mooktakim on Tuesday June 13, 2017 @09:49AM (#14544661)
If anyone, like me, is wondering what "yes" is used for. You can use to pipe "y" to commands that require interactivity, so if you just want to say "y" to all the inputs, you can use "yes" to do this:

  yes | rm -r large_directory

  yes | fsck /dev/foo
Re:How is GNU `yes` so fast? by Infernal on Tuesday June 13, 2017 @10:10AM (#14544793)
On my quad-core MacBook, I've used "yes" in four different terminals as a way to quickly test a 100% CPU load.
Re:How is GNU `yes` so fast? by blacksmith_tb on Tuesday June 13, 2017 @02:15PM (#14547166)
Yes (so to speak), you can also do 'yes &' multiple times to create lots of background load (and then 'pkill yes' before anything melts...)
Re:How is GNU `yes` so fast? by teapot01 on Tuesday June 13, 2017 @10:04AM (#14544744)
I know its only an example but why

   yes | rm -r <>
and not

    rm -rf <>
Re:How is GNU `yes` so fast? by mooktakim on Tuesday June 13, 2017 @10:35AM (#14544981)
I believe "yes" has become less useful over the years, with flags like force and quiet solves this now.
Re:How is GNU `yes` so fast? by x1798DE on Tuesday June 13, 2017 @10:12AM (#14544796)
I think rm -rf would also suppress errors in addition to confirmation messages, so presumably if you want a "soft" force...
Re:How is GNU `yes` so fast? by eridius on Tuesday June 13, 2017 @03:34PM (#14547874)
No it doesn't.

  > rm -rf foo/bar
  rm: foo/bar: Permission denied
Re:How is GNU `yes` so fast? by mnarayan01 on Wednesday June 14, 2017 @09:11AM (#14552434)
If foo/bar does not exist, it should be silent. Via http://pubs.opengroup.org/onlinepubs/007904975/utilities/rm.... on the -f option:

> [...] Do not write diagnostic messages or modify the exit status in the case of nonexistent operands. [...]

Re:How is GNU `yes` so fast? by eridius on Wednesday June 14, 2017 @01:44PM (#14554474)
Yes, but that's the only error it suppresses, and that's because "not existing" isn't really an error for a tool that's trying to delete something. In my example foo/bar existed but I didn't have permissions to delete it, and as you'll see it printed out that error.
Re:How is GNU `yes` so fast? by euske on Tuesday June 13, 2017 @10:02AM (#14544722)
I sometimes do

   yes "" | cat -n
to generate a sequence number.
Re:How is GNU `yes` so fast? by cauterize on Tuesday June 13, 2017 @10:05AM (#14544752)
Try `seq 1 n`
Re:How is GNU `yes` so fast? by JdeBP on Tuesday June 13, 2017 @02:00PM (#14547001)
euske may be using one of the operating systems (one such being mentioned on this very page) where there is no seq utility.

    JdeBP ~ $seq
    ksh: seq: not found
    JdeBP ~ $
Of course, on the one mentioned there is jot.
Re:How is GNU `yes` so fast? by moyix on Tuesday June 13, 2017 @05:31PM (#14548833)
And on bash you can simply use {1..n}:

    $ echo {1..5}
    1 2 3 4 5
If you have Bash 4.0 or above, you can include a step size:

    $ echo {1..10..2}
    1 3 5 7 9
Re:How is GNU `yes` so fast? by omgwtfpmr on Tuesday June 13, 2017 @06:43PM (#14549301)
"yes d | mail" is an excellent way to get rid of failed cron job mails.
Re:How is GNU `yes` so fast? by dtemp on Wednesday June 14, 2017 @09:57AM (#14552706)
Why wouldn't it be `mail | yes d` if you're trying to answer "d" to all of the input requests of mail?
Re:How is GNU `yes` so fast? by BenjiWiebe on Wednesday June 14, 2017 @03:32PM (#14555380)
Because you want all the d's to be sent to mail...