How can I delete everything in my Firefox history older than N days?

I set FireFox to store my history for 90 days, and I think this is slowing down the AwesomeBar. I set it to store history for 45 days, but I don't know how to delete everything in my existing history older than 45 days.


Solution 1:

In command line, you can try the following code in a bash shell with sqlite3 command : (you need bash & cygwin if you use Windows, or search the same tools in Windows)

date +%s -d "1 month ago" # the date, one month ago
1329352723

$ sqlite3 ~/mozilla/.firefox/*default/places.sqlite

sqlite> delete from moz_places
   ...> where id in (
   ...>     select id from moz_historyvisits
   ...>     where visit_date/1000000 < 1329352723
   ...> );

sqlite> delete from moz_historyvisits
   ...> where id in (
   ...>     select id from moz_historyvisits
   ...>     where visit_date/1000000 < 1329352723
   ...> );
sqlite>

Please, first backup your profile in case. ;)

Solution 2:

The long alternative from Use Linux Now:

Trimming your Firefox History

As a follow up to my previous post about how you can significantly speed up Firefox 3 by clearing your history log, here are some tips and tricks for people who, like me, do not want to vanquish their entire history log in one fell swoop.

One of the most useful and compelling reason to always keep a reasonable amount of history logged is because it powers your awesome bar. Every time you type a url into the bar Firefox searches your history to come up with a list of suggestions you can pick. In other words, clearing your history log means your awesome bar is gonna be pretty helpless for awhile.

However, the key thing to realize when trimming your history log is that Firefox chronicles EVERY nook and cranny of the web you so much as plant a toe on. This includes all your google searches, all your video searches, every image you open in your google image searches and every last email you ever read. You should be realizing by now that unless you are a very peculiar and hardcore user, there are at least SOME of all that junk that you will never need nor want to appear on your awesome bar. In other words, we can ditch some of those history without any noticeable penalty. So the next question is naturally : how do we isolate the parts of our history log that we don’t need?

This is a sticky problem of course, and how well you can do this depends on your own surfing habits. Fortunately Firefox 3 also comes packaged with a secret weapon - the awesome Firefox 3 library manager. This is a nifty tool shipped with Firefox 3 that lets you manage your browsing history and your bookmarks in a single, powerful interface. For our purposes, you can start it up either by hitting ‘Shift-Ctrl-H‘ or going to ‘History > Show All History‘.

Smart trimming with the Firefox library manager

So what is the use of this library manager? Well, among other things this tool has a reasonably powerful search function built in (see the textbox near the top?). With this search function and a little thought on our part, we can easily isolate certain types of history items and delete them off in one fell swoop. For example, if you want to delete all your google searches (I don’t personally find them useful anyway), you can type ‘google search?’ into the search form. What the manager does then is list every history item in your log which has both the keywords ‘google’ and ’search?’ in its url or title. This happens to correspond to the url structure of all google searches (and next to nothing else), so you should see all your google searches decked out like this :

enter image description here

Isolating all logged google searches

To delete all your google searches then, simply select all (ctrl-A) and hit delete. If you have alot of history stored, this may lag and take awhile. After that you’re done! You have just deleted hundreds of useless history entries (if you use google as often as me)!

In a similar manner you can delete off many different classes of history items, depending on which you consider to be useless. The trick is to identify some sort of recurring pattern (in title or in url) that can distinguish the type of history items you want to delete. Sometimes this is easy : for example if you want to delete all logs of you reading your gmail emails (which I personally think is utterly useless), you can simply search for “mail.google.com/mail” and et voila!

enter image description here

Isolating your email reading logs

Sometimes of course it may be a little more tricky. Here are some suggested keywords you can try:

  • live mail to isolate all hotmail emails and pages.
  • .jpg to isolate all jpg images you opened. Similarly you can do .gif for gif images and .png for pngs.
  • youtube watch? to isolate all youtube videos you’ve watched.
  • Turns out that whenever you click a search result in Google, Google opens an intermediate page before bringing you to your intended destination, and Firefox of course faithfully chronicles this obviously useless intermediate page. Fortunately these pages are easy to isolate. Search google url?.

What kind of junk accumulates most in your history log depends highly on your surfing habits, of course. You can get a clue of what sort of pages are occupying large portions of your history log by simply sorting the log according to the Location column. To do this, simply click on the ‘Location‘ column header.

enter image description here

Sort by Location for clues of what is occupying large portions of your history log.

Limiting the amount of history Firefox keeps

I mentioned in my earlier post that Firefox has a setting at Edit > Preferences > Privacy - “Keep my history for at least XX days”. It turns out that this is a ’soft’ limit and does not mean that your history will be deleted after XX days. We can set a ‘hard’ limit by messing abit with the Firefox config. To do this :

  • type ‘about:config‘ in your address bar. You should receive a very appropriate warning message about what we’re going to do, to which you should go ahead and promise to be careful. On agreeing you should see a dizzying array of config parameters displayed. Fortunately we are only interested in a few of them.
  • Type ‘history‘ in the filter box, and double-click ‘browser.history_expire_days‘ when it shows up.
  • Key in the amount of days you would like your history to be kept. Voila! We’re done. Firefox will now delete any history item that has not been accessed in that amount of days. You can also set a hard limit on the total amount of history items to keep by changing the value of ‘browser.history_expire_sites‘.

A more advanced alternative

It turns out that in Firefox 3, all history items (and bookmarks) are stored in SQLite databases. So people who are well versed in SQL and would like to perform more powerful queries to selectively delete your history items can try out this neat Firefox add-on called SQLite manager. IT functions as a GUI SQLite database manager much like PhpMyAdmin does for MySQL. To get to the appropriate database, simply launch the add-on (Tools > SQLite Manager), and select “places.sqlite” from the top-right drop-down list. Query as pleased from there The interface is pretty idiot proof.