accidentally concatenate a large file on a remote system

1

Every once in a while on a computer I'm ssh'd into, I will accidentally type "cat largefile.txt" and my screen will start rushing with text for the next 10 minutes. I'm always working in a screen session, so my current solution is to just log out and then log back in, and since it can go 100X faster when I'm logged out, it'll finish in the short time it takes me to type my password in again.

Is there a better way? Either involving the fact I'm in a screen session? Or a way to do this within SSH?

What doesn't work:

  • detaching from the screen session (doesn't respond until file is done outputting)
  • trying command to move to a different window in the screen session (also doesn't respond)
  • typing ctrl+C to kill cat command (also doesn't respond, probably because the command is done and the buffers just have to catch up)

Jarvin

Posted 2010-05-06T21:34:19.007

Reputation: 6 712

Answers

7

The obviously easy solution would be to not use cat. Your shell isn't a text viewer. Use less which is designed for this.

Evan Carroll

Posted 2010-05-06T21:34:19.007

Reputation: 1

Well, my system doesn't have less, but it does have more, which I use all the time when I realize I'm dealing with a large file "cat file.txt|more"... guess I should just train myself to use "more file.txt" in all situations though. No real reason to use cat when the terminal is the output. – Jarvin – 2010-05-07T19:36:35.810

1

If you're using Bash, try Ctrl-z kill % Enter

What shell are you using?

(Ctrl-c works for me, by the way.)

Paused until further notice.

Posted 2010-05-06T21:34:19.007

Reputation: 86 075

I'm using bash. Ctrl+C works if you can get it off before cat finishing processing, but by the time I realize it is super long, cat is no longer running, and it is just my display that has to catch up. So it is not that I have to kill anything, because cat is already no longer running. Ctrl-Z doesn't do anything while the file is outputting. – Jarvin – 2010-05-07T19:21:16.963

0

If you start a new screen window via ^A ^C, you will I think be able to "dodge" the oncoming buffer without having to logout & log back in again. It seems that the bottleneck is transmission of the buffer characters to your local terminal; switching to another window should alleviate the need for this effort. Not exactly a miracle cure, but it could save you some time.

intuited

Posted 2010-05-06T21:34:19.007

Reputation: 2 861

Sadly, this doesn't work. Just like all the other methods this only helps if the cat hasn't finished executing. Once it finishes and the only thing left is for the buffer to catch up, the only way I've found is just to log out. The cat usually finishes in under a second or two, so I type this almost instantly in order for it to have any effect. – Jarvin – 2010-07-06T14:51:02.460

That's interesting. Have you tried backgrounding the SSH connection? This seems unlikely to work, since it seems like you need the screen session to be detached... but then presumably you would have tried just detaching from the screen session with ^A d. How are you logging out? Anyway hitting [ENTER]``~``^Z will background the SSH session. – intuited – 2010-07-06T15:10:48.860