Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

After switching from Windows to Linux, I am left with a favourite directory containing subfolders and .url files, each file containing a few lines of text that look like this:


Since I do not have internet explorer installed on my Linux system, it is not possible for me to import the bookmarks directly to my current Firefox browser.

I was wondering if there is a quick way to extract the URL from all the .url files, together with the filenames to generate a .htm file which I can import to any modern browser.

share|improve this question
up vote 3 down vote accepted

You can do this with a little perl:

use strict;
use warnings qw(all);

use HTML::Entities qw(encode_entities);
use Config::IniFiles;
use File::Spec;

foreach my $f (@ARGV) {
    my $ini = Config::IniFiles->new( -file => $f );
    my (undef, undef, $name) = File::Spec->splitpath($f);
    $name =~ s/\.url$//;            # / # this comment un-confuses the syntax highlighter
    my $name_esc = encode_entities($name);
    my $url_esc = encode_entities($ini->val('InternetShortcut', 'URL'));
    print <<HTML
<a href="$url_esc">$name_esc</a>

That should handle everything well. You chould use grep & cut, but then you'd have to hope escaping isn't required, and that the sections in the ini-format .url file don't matter.

share|improve this answer
Thanks for this nice solution. I spent half a day crash course on perl and finally got this to work. For those uninitiated, first you need to install gcc compiler, then the two modules HTML::ENtities and Config::IniFiles. The path to these modules may be in root, and may require use lib. And @ARGV contains the input of file paths. – Question Overflow Apr 17 '13 at 7:44
@QuestionOverflow Not sure which distro you're running, but I'm surprised there weren't packages for those two modules. But I fully encourage learning at least a little Perl (or Ruby, or Python), they can quickly solve all sorts of problems like this. – derobert Apr 17 '13 at 14:36

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.