This question already has an answer here:

Let me give a bit of background to my question. I am using a terminal RSS reader newsboat which allows for the usage of macros to operate on links. For example, I have a macro running cd ~/videos && youtube-dl %u, which will download a youtube video to ~/videos. However, the output of youtube-dl will be printed in my terminal until the download is complete and for this time I cannot continue using newsboat.

I am wondering how I could phrase the command so that it is executed “somewhere else” so that I can immediately continue using the terminal from which it is run.

marked as duplicate by Christopher, Thomas, schily, G-Man, Jeff Schaller Jul 30 '18 at 22:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Why the downvote? I know that applications like youtube-dl are off-topic, but I think my question is not. – John Dorian Jul 30 '18 at 16:24
  • 1
    Please specify: Are you asking about discarding output, or are you asking about job control (e. g. running processes in the background)? – DopeGhoti Jul 30 '18 at 16:41
  • @JohnDorian Here is a +1 to compensate that :) – coderDude Jul 4 at 10:14

If you don't need the output at all then redirect it to /dev/null

yourcommand > /dev/null 2>&1

otherwise you can redirect into a file:

yourcommand > /somwhere/file 2>&1

And as you run the command from another application and you want use your news reader immediately you may want to run the command in the background. I am not sure how it works in this newsboat, but in a shell you can send programs into the backround with &

yourcommand > /somwhere/file 2>&1 &

Your question starts asking one thing, but then goes into asking about another thing.

The first thing you ask about is discarding output. This is easily done with redirection:

$ echo hello 1> /dev/null 2>&1

The second thing you ask about is running a command "somewhere else" so that you can continue using the terminal. This is called "Job Control".

You can execute any command in the background using the shell's & command separator. Compare the behavior of the following two commands:

$ sleep 5
$ sleep 5 &

If a job is already running and you need to use the terminal for other things, and you want the job to complete, you can use Ctrl-Z to suspend the job and bg to tell it to continue in the background:

$ (sleep 10; echo hello)
[1]+  Stopped                 ( sleep 10; echo hello )
$ bg
[1]+ ( sleep 10; echo hello ) &
$ echo farewell
$ fg
( sleep 10; echo hello )

This link has some fairly good reading about job control with bash.

  • I think I need both discarding output and background here. (Since I am quite a newbie, I couldn't specify the abstract concepts I was looking for, that's why I gave my concrete context.) Thank you for pointing me to the concept of job control, I will certainly read more on this topic! – John Dorian Jul 30 '18 at 16:56

To run command silently in background, which will "survive" even if terminal will be closed afterwards, use screen in detached mode:

screen -dm your_command(-s)

to reattach screen with the command running execute

screen -r

To detach reattached screen press CTRL+A+D.

Without screen you should execute your command with nohup, thus the process will run if the terminal is closed afterwards, like the screen utility:

nohup your_command(-s) &>/dev/null  &

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