2

I did Ctrl+Z bg with the intention of disowning next, but I forgot to redirect, now I cant get to my terminal because the scrolling of the output (tarballed a huge directory with verbose set).

How do I get a prompt when STDOUT from tar is filling the screen and I already sent it to the background?

I am using Bash 4.

4

You actually have a prompt already, you just can't see it because it's scrolled off screen.

The simplest thing to type is probably Ctrl-C (to kill any partial line you've typed at the prompt), fg, enter, Ctrl-Z which will bring it back to the foreground then suspend it again. Simple is nice in this case as you're doing it blindly.

It may take a few seconds to work, as your terminal is struggling to keep up with the output.

You can see clearly what this does by using a command that spews to the terminal slowly (note that my PS1 includes $? when non-zero):

anthony@Zia:~$ perl -E 'say "ha" while sleep(1)'
ha
ha
^Z
[1]+  Stopped                 perl -E 'say "ha" while sleep(1)'
anthony@Zia:~ [$?=148]$ bg %1
[1]+ perl -E 'say "ha" while sleep(1)' &
ha
anthony@Zia:~$ ha
ha
ha
ha
ha
^C
anthony@Zia:~ [$?=130]$ ha
fha
g
perl -E 'say "ha" while sleep(1)'
ha
^Z
[1]+  Stopped                 perl -E 'say "ha" while sleep(1)'
anthony@Zia:~ [$?=148]$ 

At this point, you have it stopped again, and can do whatever you'd like with it.

  • 1
    Use Ctrl-U to kill whatever you've typed so far. – glenn jackman Jan 15 '14 at 22:45
  • @glennjackman Ctrl-U won't work if you happen to have managed to hit the left arrow key when typing blidly (or control-A, or any other way of not being on the last character). You could do control-E, control-U or control-U, control-K, but that's more keystrokes. – derobert Jan 15 '14 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.