2

I have been using an & at the end of some commands, to free up the terminal. However, if it requires sudo, it doesn't work. I can get around this by running a random sudo command before it, but this is a pain, and I could also type the password in the command but this is insecure. Is there any alternative way of getting these commands to work.

Thanks.

1 Answers1

5

Essentially what you're doing , is putting command into background with &. There is a manual way to do so. Here's an example with sudo apt-get update

  1. Run sudo apt-get update as usual, enter password.
  2. As soon as command starts, press Ctrl+Z to pause the process
  3. Run bg command to put the stopped job into background.

Notice that the output still will be displayed to stdout. If it is not essential, use &> /dev/null redirection appended to the command to hide the output.

Alternative way, would be to run the shell with sudo privilleges, and run commands with -c flag, like so:

sudo bash -c 'apt-get update &>/dev/null  & '