Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

54 votes
6 answers
29857 views
What is the point of the "yes" command?
There is a `yes` command in unix/linux which basically infinitely prints `y` to the `stdout`. What is the point of it, and how is it useful?
There is a yes command in unix/linux which basically infinitely prints y to the stdout. What is the point of it, and how is it useful?
Cemre (667 rep)
Sep 6, 2012, 01:01 PM • Last activity: Feb 5, 2025, 05:12 AM
29 votes
2 answers
5674 views
Why does "yes&" crash my Bash session?
"Yes, and..." is a wonderful rule-of-thumb in improvisational comedy. Not so much in the UNIX world. When I run the admittedly silly `yes&` command, I cannot interrupt it. The terminal crashes or gets stuck into a loop. I expect the `yes` process to be suspended immediately, since any process in the...
"Yes, and..." is a wonderful rule-of-thumb in improvisational comedy. Not so much in the UNIX world. When I run the admittedly silly yes& command, I cannot interrupt it. The terminal crashes or gets stuck into a loop. I expect the yes process to be suspended immediately, since any process in the background should suspend if attempting to write to stdout, but it doesn't seem to be the case, and I'm wondering why.
Sebastian Carlos (262 rep)
Jul 6, 2023, 07:17 AM • Last activity: Jul 7, 2023, 04:45 PM
18 votes
1 answers
7417 views
What happens when writing gigabytes of data to a pipe?
Let's say I have a makefile with a recipe called `hour_long_recipe`, which as its name suggests takes an hour to run. At random points throughout the recipe it asks yes/no questions. Let's say it asks 10 questions in total. One possible (and often recommended) way to run it is: yes | make hour_long_...
Let's say I have a makefile with a recipe called hour_long_recipe, which as its name suggests takes an hour to run. At random points throughout the recipe it asks yes/no questions. Let's say it asks 10 questions in total. One possible (and often recommended) way to run it is: yes | make hour_long_recipe which answers all questions with y. However, from my understanding, yes keeps outputting to its stdout at [up to 10.2 GiB per second](https://www.reddit.com/r/unix/comments/6gxduc/how_is_gnu_yes_so_fast/) regardless of whether make is actually using that data from its stdin. Even if it was just 10 MiB/s (much slower than any implementation of yes if that reddit thread is to be believed), during the course of an hour it would add up to over 35 GiB, of which just 20 bytes will be read. Where does the data go? It's possible to save it to disk but that's wasteful, and if the disk fills up fast enough it can even cause make to fail. Presumably the operating system will stop it from getting to that, but how? What is the limit, and what happens when that limit is reached?
NeatNit (291 rep)
Dec 31, 2020, 01:20 PM • Last activity: Jan 28, 2023, 11:06 AM
3 votes
1 answers
887 views
Can you rescue a shell from an accidental "yes" command?
**Scenario**: I'm running a bunch of commands, some of which prompt for "yes/no" answers. I accidentally type `yes` as a *command* instead of as a response to a prompt. OOPS. Now my shell looks like this: ``` $ yum install -y something-important ... useful output I want to go back and refer to, perh...
**Scenario**: I'm running a bunch of commands, some of which prompt for "yes/no" answers. I accidentally type yes as a *command* instead of as a response to a prompt. OOPS. Now my shell looks like this:
$ yum install -y something-important
... useful output I want to go back and refer to, perhaps multiple times
$ yes
y
y
y
y
y
y
y
y
y
y
y
... there are tens of thousands of lines... oh god, Y??
I successfully halt the yes command after realizing what happened, but the damage is already done. I was in the middle of an intense shell session, and now I've lost the ability to scroll back up for relevant output! Obviously the previous text is all still there, but it's essentially inaccessible because it's dwarfed by all the y. Something like clear will help remove the unsightly y torrent from my screen, but it won't help me get back to the previous session state. **How can I rescue this session's previous output to still be useful?**
Indigenuity (133 rep)
Jun 22, 2022, 09:15 PM • Last activity: Jun 23, 2022, 11:30 AM
0 votes
0 answers
185 views
Inquirer program answer questions by piping
Hi I have written this program with `inquirer.js` it has a list question and after that a text input. I want to answer both questions with piping. If I just keep the list question, I can easily use `yes 1 | command` and it selects the first option and I'm done. But keeping both questions same comman...
Hi I have written this program with inquirer.js it has a list question and after that a text input. I want to answer both questions with piping. If I just keep the list question, I can easily use yes 1 | command and it selects the first option and I'm done. But keeping both questions same command passes the first question just fine but on the text one it would keep blinking 1 forever. Using echo "something" | command surprisingly selects default on the first question and leaves the second one alone, though it doesn't wait for user input it's like it has inputted nothing in there but has pressed enter for both questions really weird. Using yes '' | command doesn't get stuck and behaves exactly as above example. Using yes '1\nhello\n' | command answers the first question fine and the second question keeps blinking between 1 and hello forever. I have no other idea what to do now. Any help would be appreciated.
Steve Moretz (101 rep)
Apr 27, 2022, 09:53 PM • Last activity: Apr 28, 2022, 05:34 AM
68 votes
3 answers
10831 views
How does `yes` write to file so quickly?
Let me give an example: $ timeout 1 yes "GNU" > file1 $ wc -l file1 11504640 file1 $ for ((sec0=`date +%S`;sec > file2; done $ wc -l file2 1953 file2 Here you can see that the command `yes` writes `11504640` lines in a second while I can write only `1953` lines in 5 seconds using bash's `for` and `e...
Let me give an example: $ timeout 1 yes "GNU" > file1 $ wc -l file1 11504640 file1 $ for ((sec0=date +%S;sec> file2; done $ wc -l file2 1953 file2 Here you can see that the command yes writes 11504640 lines in a second while I can write only 1953 lines in 5 seconds using bash's for and echo. As suggested in the comments, there are various tricks to make it more efficient but none come close to matching the speed of yes: $ ( while :; do echo "GNU" >> file3; done) & pid=$! ; sleep 1 ; kill $pid 3054 $ wc -l file3 19596 file3 $ timeout 1 bash -c 'while true; do echo "GNU" >> file4; done' $ wc -l file4 18912 file4 These can write up to 20 thousand lines in a second. And they can be further improved to: $ timeout 1 bash -c 'while true; do echo "GNU"; done >> file5' $ wc -l file5 34517 file5 $ ( while :; do echo "GNU"; done >> file6 ) & pid=$! ; sleep 1 ; kill $pid 5690 $ wc -l file6 40961 file6 These get us up to 40 thousand lines in a second. Better, but still a far cry from yes which can write about 11 million lines in a second! So, **how does yes write to file so quickly?**
Pandya (25613 rep)
Jan 24, 2016, 05:22 AM • Last activity: Nov 2, 2021, 09:35 AM
0 votes
1 answers
853 views
What happens when piping the `yes` to another command?
If the `yes` command echos "y" continuously until killed, then it will never get done right? If it will never get done then how does it pipe it's output to the next command??
If the yes command echos "y" continuously until killed, then it will never get done right? If it will never get done then how does it pipe it's output to the next command??
yaquawa (111 rep)
Mar 30, 2020, 01:46 AM • Last activity: Mar 31, 2020, 12:57 AM
3 votes
1 answers
34434 views
yes | apt-get install --fix-broken
I am trying to write a non-interactive system update script. Question: if the following works well: yes | dpkg --configure -a will the following work also very well?: yes | apt-get install --fix-broken
I am trying to write a non-interactive system update script. Question: if the following works well: yes | dpkg --configure -a will the following work also very well?: yes | apt-get install --fix-broken
Vlastimil Burián (30515 rep)
Nov 13, 2016, 12:48 PM • Last activity: Jun 28, 2019, 06:30 PM
3 votes
2 answers
2508 views
How to use `yes` with `xargs -p`?
Let's say I have `ls | xargs -n1 -p rm`, how do I use `yes` or `yes n` to automatically answer the questions generated by the `-p` flag? I tried `yes n | (ls | xargs -n1 -p rm)` but didn't work. **UPDATE**: The question is not really about `rm`, it's about how to use `yes` properly. I have an alias...
Let's say I have ls | xargs -n1 -p rm, how do I use yes or yes n to automatically answer the questions generated by the -p flag? I tried yes n | (ls | xargs -n1 -p rm) but didn't work. **UPDATE**: The question is not really about rm, it's about how to use yes properly. I have an alias or a function that uses xargs -p and I like the fact that it asks me and shows me what it's doing before doing it. When I know what it will do, I would like to be able to use yes to automatically go through all of the xargs -p in the function. So even though the example uses rm, it's not really about it. Also just to be extra clear, I don't want to modify my alias or function to use or not use -p. I rather just input yes externally. Tbh I thought that something like yes | some_function_asking_me_questions or some_function_asking_me_questions <( yes ) would have worked, but it didn't. **2nd EDIT**: Another example: I have an alias to list AWS SNS topics in a region like:
-sh
alias delete_snstopics="list_sns | cut -f 2 | xargs -n1 -p aws sns delete-topic --topic-arn "
Then I have a function that for each region in AWS finds and prompts for deletion for those SNS topics. I want to see the aws sns delete-topic --topic-arn $1 that the xargs would run, because the id of the SNS topic is different every time and if something goes wrong I can match up the SNS id in the web console. Moreover at times I might not want to delete the SNS topic in a particular region. And that's why I want to use yes with this function, so that I can use the same function for partial deletion and full deletion, and still get useful output. Makes sense?
Gabriel (139 rep)
Aug 24, 2015, 07:09 PM • Last activity: May 3, 2019, 06:25 PM
1 votes
1 answers
316 views
If /dev/random is implemented as a pseudo-device, why isn't "yes"?
yes produces a stream of "y" chars, or other requested. If Unixen have a pseudodevice for random numbers, why not useful streams like this too?
yes produces a stream of "y" chars, or other requested. If Unixen have a pseudodevice for random numbers, why not useful streams like this too?
interstar (1127 rep)
Apr 21, 2018, 03:22 PM • Last activity: Nov 4, 2018, 06:42 PM
11 votes
1 answers
28108 views
How to pipe a 'yes' or 'y' into a program while invoked with 'sudo' in bash?
How to pipe a `Y` or `yes` to a program while invoking with `sudo`? We can type like this yes | command yes | yum update How to pipe the `y` from `yes` into a program via `sudo` like the following? yes| sudo command The `y` from `yes` is be passed into `command` and should go into `sudo` and `sudo`...
How to pipe a Y or yes to a program while invoking with sudo? We can type like this yes | command yes | yum update How to pipe the y from yes into a program via sudo like the following? yes| sudo command The y from yes is be passed into command and should go into sudo and sudo shall ask for password normally. How can I do this?
Abhik Bose (2138 rep)
Dec 15, 2017, 01:41 PM • Last activity: Dec 15, 2017, 09:52 PM
1 votes
1 answers
6516 views
How to exit out of a 'yes' loop
Using the command `yes` you can make a loop in the Linux terminal.&#160; How do you exit out of said loop?&#160; (I tried Ctrl + C but it didn't work).
Using the command yes you can make a loop in the Linux terminal.  How do you exit out of said loop?  (I tried Ctrl+C but it didn't work).
John D (121 rep)
Nov 3, 2017, 03:21 PM • Last activity: Nov 4, 2017, 12:03 AM
Showing page 1 of 12 total questions