21

How I would go about opening multiple URLs from a text file as different tabs in Firefox/Chrome? My text file is just a list of URLs, one per line:

http://www.url1.com
http://www.url2.com
http://www.url3.com
http://www.url4.com

5 Answers5

17

Firefox uses the new-tab command, so you could pass the URLs in the file to the browser like so:

while read line; do
    firefox --new-tab "$line"
done < textfile.txt

With Chrome, the syntax is:

google-chrome "$line"
jasonwryan
  • 73,126
  • 2
    On OS X you can make this work with Chrome with something like alias google-chrome='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'. Probably similar for Firefox. – David Winiecki Dec 11 '14 at 20:58
  • 1
    @DavidWiniecki If trying to use the alias in a script, I had to specify "shopt -s expand_aliases" in the script file. Otherwise I was getting "command not found" error, even when I was able to run the alias command successfully from the command line. – blakemade Apr 11 '20 at 23:20
  • This is exactly what xargs was made for! :-) https://unix.stackexchange.com/a/139842/32558 It's even POSIX: https://pubs.opengroup.org/onlinepubs/009695399/utilities/xargs.html – Ciro Santilli OurBigBook.com Jan 31 '21 at 22:16
7

I think this may be a nice solution:

xargs -n1 firefox -new-tab < allmyURLs.txt

or:

xargs chromium-browser --new-tab < allmyURLs.txt

The -n1 is needed on Firefox 84 because you need one -new-tab argument for every URL.

Ciro Santilli OurBigBook.com
  • 18,092
  • 4
  • 117
  • 102
  • 1
    "$line" is wrong in this answer: xrag applies the strings from the input file each as parameter to its subcommand. I corrected the answer accordingly. – halloleo May 25 '15 at 03:02
  • I needed xargs -L1 on Firefox 84: https://superuser.com/questions/772153/how-to-open-multiple-urls-in-chrome-firefox-and-then-save-them-individually/1622388#1622388 – Ciro Santilli OurBigBook.com Jan 31 '21 at 22:50
3

If there is only a number changing in the url, then you can change the number as given below. If they are different urls then you can use jasonwryan's solution.

google-chrome --new-tab http://www.url{1..4}.com

The above command will expand as below in new google chrome tabs:

http://www.url1.com http://www.url2.com http://www.url3.com http://www.url4.com

This solution is typically to load all pages where you would have to do next, next to go through the pages.

Ciro Santilli OurBigBook.com
  • 18,092
  • 4
  • 117
  • 102
1

okay... so here was a wildly more efficient script for my use.

#!/bin/bash

#make sure an instance of firefox starts up first firefox #let it load sleep 2 #open the links cmd="firefox" while read link; do cmd+=" --new-tab ${link}" done < ./source_of_links.txt ${cmd}

this works much faster as it executes only one firefox command. if you try to open a new link with firefox in a loop - you may run into a bottle neck like I did... with this above script - all the links always open at once.

altruios
  • 121
0

On windows / cygwin... this worked for me:

#!/bin/bash -xe

browser="/cygdrive/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"

clients="fb aapl nflx "

for i in $clients
do
        "$browser" --new-tab https://asite.com/dashboard/$i
done