LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-05-2013, 12:55 PM   #1
whitehunk
LQ Newbie
 
Registered: Dec 2009
Location: Horsens, Denmark
Distribution: xubuntu "trusty" 14.04
Posts: 12

Rep: Reputation: 0
search firefox bookmarks from terminal


i would like to know if i can search my firefox bookmarks by keywords from the terminal ? Sure, there are some fancy extension that offers to help if i install it, but i would like to do it from my terminal anyway ;-) This is linux, anything is possible :-)
 
Old 11-05-2013, 02:28 PM   #2
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
If you are in the directory where the Firefox files are kept for the profile whose book marks you wish to search, and Firefox is not running, this command:

Code:
sqlite3  places.sqlite  'select * from moz_places where title like "%some_keyword%";'
would list all book mark records that contain the phrase some_keyword in the title field stored with the book mark.

With that information you can apply sqlite3 syntax to examine the schema to choose the field to search, the fields to display, and in what format, for your particular situation.

I would avoid doing this while the particular instance of Firefox is running, whose book marks you wish to search.
 
Old 11-05-2013, 03:32 PM   #3
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 97
Quote:
Originally Posted by rigor View Post
I would avoid doing this while the particular instance of Firefox is running, whose book marks you wish to search.
Or as an alternative (perhaps slightly safer)...

Firefox saves daily backups of your bookmarks in json files. Put this function into your .bashrc / .profile file:

Code:
bmfind() {
        for bmdir in $(find ~/.mozilla/firefox -name bookmarkbackups); do
                bmfile=${bmdir}/$(ls -rt ${bmdir} | tail -1)
                grep -o '{[^}]*}' $bmfile |\
                        sed -n 's/.*"title":"\([^"]*\)".*"uri":"\([^"]*\)".*/\1\t\2/p'
        done | grep -i $1 | sort | uniq
}
$bmfile will be set to the most recent backup (for each profile, if you have more than one) The first grep command then cuts out each json element and the sed command extracts the "title" and "uri" from these:

Code:
$ . ~/.bashrc # make it available immediately
$ bmfind tutorial
Help and Tutorials	http://www.mozilla.com/en-US/firefox/help/
Symfony2 Tutorial	http://tutorial.symblog.co.uk/
 
Old 11-05-2013, 11:34 PM   #4
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
Quote:
Originally Posted by Robhogg View Post

Firefox saves daily backups of your bookmarks in json files. ...
The daily part of that is why, not knowing if the OP needs up to the moment data, I didn't mention the JSON.

Perhaps without additional details about what the overall purpose is, of the Command Line based search for keywords, more of an overview of possible general ways to approach it is better.

It may be that doing it from the Command Line is just an Intellectual Exercise, for the fun of it.

Either way whitehunk, you might want to consider the following.

sqlite3 has locking capabilities to try to prevent database corruption. Yet virtually nothing is perfect, which is why I cautioned against using the sqlite3 database used by FF ( Firefox ) , when FF is running. For some details, please see the section on, how to corrupt your database, in the document on sqlite3 locking, at sqlite.org.

There's the JSON approach that, used at a randomly picked time of day, may be out of date. It might produce some garbage output as well, if you happen to catch things just right as FF is writing the JSON.

It's also possible to use FF itself to export up to the moment book marks as HTML, then search through the output file by keyword.

A gawk program such as this:

Code:
/<DT><A HREF="http/  { a_elem_residue = substr( $4 , 9 )  ;  quote2_pos = index(  a_elem_residue , "\042" ) ;  print  "TITLE:  "  $(NF-2)  "   URI:  "  substr( a_elem_residue , 1 , quote2_pos - 1 )  }
can grab the Title and Uri from the output HTML file.

In a sense, you can already search for book marks in FF by keyword in some bookmark fields, without an extension. You can also assign tag(s) to book marks, then search for the tags.

If you already have a large number of book marks, you could extend a Command Line approach to searching by keyword, or combination of keywords, to apply tags to large numbers of existing book marks in a single pass, chosen by the keyword search. Then repeat the procedure for each keyword, or combination of keywords. The tags could potentially by applied via sqlite3 when FF is not running.

If you're worried about whether or not extensions can be trusted, I wouldn't go to some web site with which I was unfamiliar, like joe_bobs_evil_extension_site.com , download extensions and then use them. But being a bit careful, and downloading from Mozilla, I've never encountered a deliberately malicious extension.

Finally, if you won't use an extension, or if you want to search in some more complicated fashion than FF ( or perhaps any existing extension ) already allows, if you can write a command line facility to search by keyword, odds are you can add similar functionality to FF, by writing your own extension to FF that searches the way you want.

Hope this helps!

Last edited by rigor; 11-05-2013 at 11:40 PM.
 
Old 11-06-2013, 05:40 AM   #5
whitehunk
LQ Newbie
 
Registered: Dec 2009
Location: Horsens, Denmark
Distribution: xubuntu "trusty" 14.04
Posts: 12

Original Poster
Rep: Reputation: 0
Smile thanks

Thanks to both of you for the very detailed reply... My reasoning behind asking this question was indeed to use it as an "intellectual exercise" and get better at the promt.. desktops are nice, but someday i may well find me in an situation where my preferred desktop fail.. then it would be nice to be to be a little more at home in the terminal. Thanks again
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
firefox bookmarks ARCIS_house Linux - Software 6 04-17-2014 01:54 PM
Firefox bookmarks.html not showing correct bookmarks even though file is identical. php Ubuntu 7 11-08-2008 04:12 PM
Bookmarks in Firefox 2.10 cegres Linux - Newbie 4 02-10-2008 07:45 AM
search bookmarks titanium_geek LQ Suggestions & Feedback 13 11-04-2006 02:24 AM
firefox bookmarks.... alaios Linux - Software 2 08-17-2005 11:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration