Mac OS X – Export Google Chrome Browsing History to CSV File from the Terminal

This post is just for my own personal reference, but you can use it too if you like. Just make sure to change the “UserName” below to whatever that user’s home directory is. I’ve mashed the code together from the following sources, changed it to export in csv format (making it easier to import into Excel or Open Office for further manipulation), made it into a one-liner for sake of ease, put the data in ascending order based on last URL visit date, and converted the dates into human readable format.
http://superuser.com/questions/359996/export-history-from-chome-browser
http://stackoverflow.com/questions/2562092/how-to-access-google-chrome-browser-history-programmatically-on-local-machine
http://stackoverflow.com/questions/5585849/may-i-run-a-script-on-sqlite-command-line
http://linuxsleuthing.blogspot.com/2011/06/decoding-google-chrome-timestamps-in.html

/usr/bin/sqlite3 -csv -header /Users/UserName/Library/Application\ Support/Google/Chrome/Default/History "SELECT urls.id, urls.url, urls.title, urls.visit_count, urls.typed_count, datetime((urls.last_visit_time/1000000)-11644473600, 'unixepoch', 'localtime') AS last_visit_time, urls.hidden, urls.favicon_id, datetime((visits.visit_time/1000000)-11644473600, 'unixepoch', 'localtime') AS visit_time, visits.from_visit, visits.visit_duration, visits.transition, visit_source.source FROM urls JOIN visits ON urls.id = visits.url LEFT JOIN visit_source ON visits.id = visit_source.id order by last_visit_time asc;" > history.csv

Leave a Reply