I am using Ubuntu 16.04 LTS. I want to download some YouTube videos. I came to know about the command line tool youtube-dl from this question. As mentioned by Yasser, using the command,

youtube-dl youtube.com/videolink --format mp4

I am able to download those video files in mp4 format.

Now I want to download ten videos from different channels. I have a text file with the YouTube links and the names by which I want to save them. The text file with name data.txt looks like,

http://youtube.com/link1    name1
http://youtube.com/link2    name2
http://youtube.com/link3    name3 
.........                   ......
.........                   ......
http://youtube.com/link10    name10

Now I want to run the youtube-dl command only once so that it takes the arguments from that text file automatically and save them with the required names.

If I have only the links in data.txt, i.e.,


I am able to download the videos using the command only once with option -a,

youtube-dl --format mp4 -a data.txt

But I could not rename them simultaneously. From man page of youtube-dl I found that there is an option --output to set the filename.

How could I do that?

  • Can't you just place every url one after another? Like youtube-dl youtube.com/videolink youtube.com/videolink2 youtube.com/videolink3
    – Noosrep
    Mar 22, 2017 at 11:15
  • It's manpage reads: SYNOPSIS: youtube-dl [OPTIONS] URL [URL...], so yes, it should be possible to simple write one after the other.
    – M. Becerra
    Mar 22, 2017 at 11:20
  • Im writing a script to accomplish what you asked, do you want to be able to set the location where the file is gonna be stored?
    – M. Becerra
    Mar 22, 2017 at 11:30
  • Yes. It would be nice to set the location.
    – ddas
    Mar 22, 2017 at 11:50
  • @Becerra, do you have any positive news?
    – ddas
    Mar 31, 2017 at 6:56

2 Answers 2


If you are only renaming files because you don't like the style by which youtube-dl names them, then you can use --output (or -o) with a template to customize the way it names all the files from Youtube metadata.

For example, -o %(title)s.%(ext)s will cause it to leave out the Youtube IDs from all of the filenames.

There are a lot of options, which may depend on your version of youtube-dl, so full details on this can be found at the terminal by typing:

man youtube-dl

However if you do want to name each file individually, you could instead run youtube-dl once for each line in the text file like this:

(while read URL NAME; do [ "$URL" ] && youtube-dl --format mp4 -o "$NAME" "$URL"; done) < data.txt

For each line, split it at the first run of one or more tabs and spaces into a URL and NAME, then if the line is not blank, pass them to youtube-dl. If the line just has a URL, the file will not be renamed.


Your solution is to use config file. On Linux and OS X, the system wide configuration file is located at /etc/youtube-dl.conf and the user wide configuration file at ~/.config/youtube-dl/config. Note that by default configuration file may not exist so you may need to create it yourself. I did not have any in my ~/.config, so I had to create my configuration file. In there you can pass any argument you'd usually use with inline command in youtube-dl. Good use case is authentication with .netrc file and common use is the output format. Here is sample config file:

#Authentication with .netrc file

# Save all videos in a directory named vimeo in your home directory
-o "~/Vimeo/%(title)s %(upload_date)s i%(id)s.%(ext)s"

# Download best format available via direct link over HTTP/HTTPS protocol
-f '(bestvideo+bestaudio/best)[protocol^=http]'

# Simple file name

You can use --ignore-config if you want to disable the configuration file for a particular youtube-dl run. In essence, just like you're using -a switch to batch download, you can use config file to batch rename your downloads and tons of other customizations if you wish. Everything is documented with nice examples at youtube-dl official documentations, specially read the CONFIGURATION & OUTPUT TEMPLATE sections.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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