5 ms·
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 t
by mooktakim 9y ago
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
- euske 9y agoI sometimes do yes "" | cat -n to generate a sequence number.
- cauterize 9y agoTry `seq 1 n`
- JdeBP 9y agoeuske 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.
- moyix 9y agoAnd 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
- teapot01 9y agoI know its only an example but why yes | rm -r <> and not rm -rf <>
- x1798DE 9y agoI think rm -rf would also suppress errors in addition to confirmation messages, so presumably if you want a "soft" force...
- eridius 9y agoNo it doesn't. > rm -rf foo/bar rm: foo/bar: Permission denied
- mnarayan01 9y agoIf foo/bar does not exist, it should be silent. Via http://pubs.opengroup.org/onlinepubs/007904975/utilities/rm.html 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. [...]
- eridius 9y agoYes, 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.
- mooktakim 9y agoI believe "yes" has become less useful over the years, with flags like force and quiet solves this now.
- Infernal 9y agoOn my quad-core MacBook, I've used "yes" in four different terminals as a way to quickly test a 100% CPU load.
- blacksmith_tb 9y agoYes (so to speak), you can also do 'yes &' multiple times to create lots of background load (and then 'pkill yes' before anything melts...)
- omgwtfpmr 9y ago"yes d | mail" is an excellent way to get rid of failed cron job mails.
- dtemp 9y agoWhy wouldn't it be `mail | yes d` if you're trying to answer "d" to all of the input requests of mail?
- BenjiWiebe 9y agoBecause you want all the d's to be sent to mail...