Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am attempting to pipe the output from youtube-dl to xargs as I would like to name the downloaded file with the title extracted from the first command. however am having trouble doing so. The command I am using is as follows;

youtube-dl --get-title "Youtube URI" | xargs youtube-dl -o {} "YouTube URI"

share|improve this question
Xargs can't deal with spaces ' and " unless you pass the -0 flag. Also, I don't know youtube-dl, but maybe it doesn't take standard input, so xargs would be useless. – Bruno9779 Jun 11 '12 at 23:35
@Bruno9779 - What do you mean by space ' and "? How would I know whether an application like youtube-dl takes standard input? – PeanutsMonkey Jun 11 '12 at 23:54
I mean the space character, quotes and double quotes. Read the man pages of xargs for more on that and stdi/o (I don't want to paste all that here). It looks like youtube-dl takes only URLs as stdin, so your command can't work IMO. Still, try with a -0 flag after xargs first, you never know – Bruno9779 Jun 12 '12 at 0:56
@Bruno9779: -0 would produce a file name with the ending newline character in it, which is allowed, but often annoying. If no other delimiter is given with -d, xargs defaults to \n ("newline") which is appropriate in this case. – Daniel Andersson Jun 12 '12 at 7:06
up vote 3 down vote accepted

To address your specific question about xargs, you need to specify that you want to use the {} placeholder:

youtube-dl --get-title "Youtube URI" |\
    xargs -I{} youtube-dl -o {} "Youtube URI"

See man xargs for more info, and what switches are also implied by -I.

Since it's only a single argument, it would be more straightforward to use substitution:

youtube-dl -o "$(youtube-dl --get-title "Youtube URI")" "Youtube URI"

Note that these constructions will give you a file without appropriate file extension.

The most straightforward way to accomplish your actual task would as mentioned be to use the built-in title naming option:

youtube-dl -t "Youtube URI"

as described in man youtube-dl. This will also produce the correct file extension for the video file.

share|improve this answer
Thanks. I don't quite follow what you mean by I need to specify that I want to use the {} placeholder. My understanding is that {} is a placeholder for the output produced in the preceding command. – PeanutsMonkey Jun 14 '12 at 0:31
@PeanutsMonkey: No, usually xargs just appends all incoming arguments after the given command. echo foo bar | xargs -d' ' echo baz will print baz foo bar on a single line; the arguments have been appended to a single echo call. The {} placeholder is a special construct, and needs to be explicitly activated with -I, as it says in the manual. – Daniel Andersson Jun 14 '12 at 8:05

I have been reading youtube-dl man pages: what you are trying to do is much simpler than that, you just need the -t,--title flag.

youtube-dl --title "Youtube URL"


youtube-dl -t "Youtube URL"

share|improve this answer
The reason I want to avoid youtube-dl --title "YouTube URL" is because it has a different output to that of youtube-dl --get-title "Youtube URL". – PeanutsMonkey Jun 14 '12 at 0:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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