Is there a command to show Firefox history from the Terminal ?
without the need to Enter Firefox history graphically .
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this communityThis page describes what user-specific information is stored by Firefox and where. (And this is what Mozilla's help has to say on viewing .sqlite files.)
It lists three types of history:
Bookmarks and Browsing History: The places.sqlite file contains all your Firefox bookmarks and the list of all the websites you’ve visited ...
Autocomplete history: The formhistory.sqlite file remembers what you have searched for in the Firefox search bar and what information you’ve entered into forms on websites ...
Download history: The downloads.sqlite file remembers what you have downloaded. ...
As you can see, all three histories are not simple text files but database files in sqlite
format.
One way to view .sqlite
files is by using sqlite3
(sudo apt-get install sqlite3
).
Open a terminal and cd
to the folder containing what you want to view. In my case, that is ~/.mozilla/firefox/w4wcp85s.default
.
ls *.sqlite
lists the sqlite files.
Run sqlite3 places.sqlite
(if places.sqlite is what you want to view). You'll see something like this:
$ cd ~/.mozilla/firefox/w4wcp85s.default
$ sqlite3 places.sqlite
SQLite version 3.7.17 2013-05-20 00:56:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>
Now, there are several things you can do. (Use Ctrl+D to exit sqlite3).
For example, typing .tables
and pressing Enter gives me:
sqlite> .tables
moz_anno_attributes moz_favicons moz_items_annos
moz_annos moz_historyvisits moz_keywords
moz_bookmarks moz_hosts moz_places
moz_bookmarks_roots moz_inputhistory
sqlite>
To view the contents, type SELECT * FROM table_name;
(where table_name
is the name of the table you wish to view; note the ;
) and press Enter. It's quite likely that the output won't be understandable but that is not the fault of sqlite3.
To show you an example that does provide decent output, look at stylish.sqlite
(if you use the Stylish extension):
$ ~/.mozilla/firefox/w4wcp85s.default $ sqlite3 stylish.sqlite
SQLite version 3.7.17 2013-05-20 00:56:22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
style_meta styles
sqlite> SELECT * FROM styles;
6||||YouTube|/* AGENT_SHEET */
/* ▓▓ NIGHTSHIFT - eye care: ▓▓
▓▓_http://userstyles.org/styles/18192/nightshift-eye-care_▓▓ */
@namespace url(http://www.w3.org/1999/xhtml);
@-moz-document regexp("https?://www.youtube.com/.*") {
body,html {min-height: 100%!important; }
html, body{background-color:#111!important}
You can do everything in just one non-interactive command if you know exactly what you want. Read The sqlite3 command line tool for more on sqlite3.
$ sqlite3 stylish.sqlite "SELECT * FROM styles;" > ~/Desktop/filename.txt
will do the needful in the example given and tee
will let you see the output on screen as well:
$ sqlite3 stylish.sqlite "SELECT * FROM styles;" | tee ~/Desktop/filename.txt
(Thanks due here.)
for DATABASE in *sqlite; do echo -e "********\n$DATABASE\n********";for TABLE in $(sqlite3 $DATABASE ".tables"); do echo -e "========\n$TABLE\n========"; sqlite3 $DATABASE "select * from $TABLE;"; done; done | grep 'stackoverflow\.com'
Or instead of grep
use less
and search inside the results.
~/.bash_history
, so I wrote a Python (3.5+) script using the Click library to make basic listing, sorting, and filtering a lot easier. You can get it from this Gist. Please leave comments there if you run into problems.
May 12, 2018 at 1:40
Here is what I ended up with (thanks to previous answers):
db=$(find "${HOME}/.mozilla/firefox/" -name "places.sqlite")
query="select p.url from moz_historyvisits as h, moz_places as p where substr(h.visit_date, 0, 11) >= strftime('%s', date('now')) and p.id == h.place_id order by h.visit_date;"
todays_urls=$(sqlite3 "${db}" "${query}")
echo "${todays_urls}" > todays_urls
| head -1
to the find
command.
On my Xubuntu 13.10 it's on
/home/myusername/.mozilla/firefox/nod2ejl8.default/places.sqlite
Or you could
find / -name 'places.sqlite
Since it's an *.sqlite file, you can install this vim plugin and use vim, search for a way to open an sqlite file from terminal. More information can be found here.
Another handy copy-and-paste one-liner based on all of the above:
(cd ~/.mozilla/firefox; for a in */places.sqlite; do sqlite3 $a "select h.visit_date,p.url from moz_historyvisits as h, moz_places as p where p.id == h.place_id order by h.visit_date"; done)
If you're on Windows, install cygwin, WSL, coreutils AND sqlite3, and then:
(cd %APPDATA%/Mozilla/Firefox/Profiles; for a in */places.sqlite; do sqlite3 $a "select h.visit_date,p.url from moz_historyvisits as h, moz_places as p where p.id == h.place_id order by h.visit_date"; done)
...Or just copy all your places.sqlite files to a flash drive, and run the first command on your pi, or a USB live booted Linux. (Find one on distrowatch)
If you want to sort or count it, you can change the SQL Query... or you can just add the following at the end of the above commandline:
Count: |wc -l
Order by date: |sort -n
Order by most visited: |cut -d\| -f2|sort|uniq -c|sort -n
Find any text or substring: |grep "youtube"
(more accurately "http://youtube.com/"
or it will match any url containing "youtube"
)
Exclude text: |grep -v "http://youtube"
Count Youtube visits: |grep "http://youtube.com/"|wc -l
You can string these together. |
is called a pipe. Welcome to Unix :-D
If you want to open all the URLs filtered, add |xargs firefox
These will work fine as long as the list of URL's will fit into RAM... if not, you will need to edit the sqlite query to accomplish the same.
grep
), you can create graphs, etc. Everything not possible inside firefox. At least not without hacking an addon.