1

For example, I type sudo apt-get update and then a long list of stuff will come up for minutes..

if I want to escape from seeing this tiresome updating and take control of bash command line again(without quitting the original command),

is there a hotkey or something like that to do it?

kwagjj
  • 2,319

2 Answers2

5

You can stop apt-get temporarily with Ctrl-Z and then restart the job in the background with the bg command.

$ apt-get foo bar ...
^Z
bash: suspended apt-get
$ bg
bash: continued apt-get
$

However, when you do you'll continue getting the output from apt-get on the terminal. It isn't possible to stop that after you've already started the command (other than with dirty hacks using a debugger). You can run other commands here, though. While the job is stopped, it is still alive but not running, so it won't make any progress but you won't see any output either.

What you may find useful is the screen or tmux commands. They let you run multiple sessions with different terminals within the same physical terminal. If you're using X, you can run additional terminal emulators or perhaps create a new tab in your current one. Whichever way, you can run apt-get update in one shell and then switch to another to continue working.

Michael Homer
  • 76,565
1

For this particular command you can generally assume it'll work without errors most of the time. In this case, you may be better off just running it like this:

  sudo apt-get update > ~/.aptget.update.log &

You can also hide all output using parenthesis:

  (sudo apt-get update > ~/.aptget.update.log &)

This can be aliased with this line to make it handy you could use:

  alias apt-update="(sudo apt-get update > ~/.aptget.update.log &)"

This lets you run the command using only 'apt-update'. Put that in your ~/.bashrc file to have it automatically run it each login.

You could also then add a custom message to remind you what it is doing:

  alias apt-update="echo \"Running apt-get update in the background. Wait a few moments for it to finish.\" || (sudo apt-get update > ~/.aptget.update.log &)"
krowe
  • 746