Bash – terminal Ctrl+s versus Ctrl+z

bashkeyboard shortcutsputtyterminal

I have, for example, a long running and verbose tar cvf /backup/backup.tar command that outputs a lot of text to the screen*. I don't necessarily want to see all of the output all of the time. I'd like to stop the text output, do other stuff, then come back to it and "resume" to see how far along it is in the backup process. I expected it to behave like

/files/big_file_1
/files/big_file_2
/files/big_file_3
# Ctrl+s
# Do other stuff
# Ctrl+q , notice big jump in progress
/home/user/.bash_history
/home/user/small_file_1
/home/user/small_file_2
/home/user/small_file_3
...

Ctrl+s stops output to the screen (and Ctrl+q resumes output to screen), whereas Ctrl+z suspends the process and I'm back to a PS1 prompt. My question is, does Ctrl+s keep the command running?

During the aforementioned tar command, I would highlight the last file TARred let it sit for a few minutes, Ctrl+q, and the next files appeared to be in the same dir, or at least in a relatively close directory.

*I'm using Putty on Windows, so if the behavior is different between that and a standard terminal on Linux/Unix I apologize.

Best Answer

My question is, does Ctrl+s keep the command running?

Yes, up to the point where the system buffers fill, and the process starts blocking to be able to write to the terminal. So, it won't run indefinitely. Plus you won't be able to run anything else in the same terminal since the output is blocked.

To switch away from the program while still keeping it possible to come back, the choices are:

  • Run another terminal on the side (another Putty, another SSH connection)
  • Run screen or tmux to multiplex multiple "windows" inside the same terminal
  • Redirect the output to a file, run the command in the background and then peek at the file when you want to: tar cvf ... > /tmp/tar.out & and tail /tmp/tar.out
Related Question