To stop background jobs, you first need to bring them to foreground by fg command. If you do want background jobs with no output on terminal, just run command > /dev/null 2>&1 &; if you want to completely disconnect them from terminal, run nohup command &; this will keep the command running, even if you close the terminal, and append the output to a file named nohup.out.
– ridgyDec 28 '16 at 19:54

1

@ridgy You might want to post an answer about that. My answer focuses on how to run youtube-dl differently, and does include information about redirection, but it doesn't address how the OP should fix the problem after running it in a way they don't want (as your comment does), nor does it give any information about job control. I'm somewhat reluctant to expand my own answer since it's already rather complicated and because I don't want to remove the primary focus from youtube-dl's options too much.
– Eliah KaganDec 28 '16 at 20:42

1 Answer
1

youtube-dl is running in the background, but it is still sending output to your terminal, and producing quite a lot of it to inform you of its progress. There are a number of ways to change this, but you'll probably either want to make youtube-dlproduce less output, or cause its output to be sent to a file (or discarded altogether) instead of appearing in your terminal.

Way 1: Run youtube-dl -q to suppress status messages.

If you don't want to see the progress messages, you can pass the -q flag (or --quiet, which does the same thing) to the youtube-dl command:

youtube-dl -q https://www.youtube.com/watch?v=NZ-ElsvYKyo &

You'd have to replace that URL with whatever you're trying to download, of course. Some messages may still be printed, including errors and warnings. But it's likely you want to see those.

If you don't want youtube-dl to produce any warnings, you can run youtube-dl with the --no-warnings flag. I don't suggest doing that, though, unless you're sure that's what you want.

Way 2: Redirect standard output of youtube-dl to a file.

To append the output to dl.log in the current directory (you can name this what you want, and it will be created if it doesn't already exist), run:

youtube-dl https://www.youtube.com/watch?v=NZ-ElsvYKyo >> dl.log &

If you want to overwritedl.log instead of appending text to the end, use > instead of >>:

youtube-dl https://www.youtube.com/watch?v=NZ-ElsvYKyo > dl.log &

Normal output will then be redirected to dl.log (or whatever file you tell it to use). Error output, however, will still be shown on your terminal. For example, when I ran that command, I got one warning printed to my terminal:

You can view the output with cat (as I've done above) at any time, to check the progress.

When you run youtube-dl without -q, it produces output that is primarily meant for a terminal. This output includes control characters that tell a terminal to erase the previous progress message, so that it may be visually replaced with the new progress message. Some ways of viewing the file, like cat dl.log, will not show the "erased" messages or the control characters. They're still part of the file, though, and you can view them with some other utilities; for example, view dl.log works.

Way 2a: Redirect the output to /dev/null to get rid of it.

If you want the output to just be discarded rather than saved in an actual file, then you can redirect it to /dev/null:

youtube-dl https://www.youtube.com/watch?v=NZ-ElsvYKyo > /dev/null &

With /dev/null, it doesn't matter if you "overwrite" (>) or "append" (>>).

This is a handy technique in general, though probably unnecessary with youtube-dl. If you want to suppress progress, you can just run youtube-dl -q instead.

Way 3: Redirect standard error, too.

Regular output and error output are separate. It's common for youtube-dl to produce both. The above method redirected only standard output. You can also redirect standard error. There's a lot you can do with redirection, including redirecting the two output streams to separate files. For our purposes here, I'll just show how to send both standard output and standard error to the same file:

The above example used &>>, which appends to dl.log. To overwrite the file instead, use &> (or >&, which also works) instead of &>>:

youtube-dl https://www.youtube.com/watch?v=NZ-ElsvYKyo &> dl.log &

Way 3a: Redirect both normal and error output to /dev/null.

If you really want to, you can redirect both standard output and standard error to /dev/null so it is all simply discarded:

youtube-dl https://www.youtube.com/watch?v=NZ-ElsvYKyo &> /dev/null &

You probably want to see actual error messages, though. If it's just status messages and warnings you don't want, then you don't need any redirection. In that case you can use youtube-dl -q --no-warnings as described above. (See Way 1.)