14

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.

8 Answers 8

3

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. ;)

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.

7
  • 2
    No need for CCleaner, Firefox can clean its own history if you want to just clean it all. Go to: Tools > Clear Recent History (that's the wording in FF3.5 before that it was Clear Private Data).
    – Eran
    Jul 30, 2009 at 16:17
  • God some people have no sense of humor!
    – Ivo Flipse
    Jul 30, 2009 at 16:17
  • @Ivo : there is no tag "humour" in the question, so everyone has to answer seriously :]
    – Gnoupi
    Jul 30, 2009 at 17:14
  • Good to see that nobody took my edit serious then...
    – Ivo Flipse
    Jul 30, 2009 at 17:45
  • 1
    I don't have time to read all that, but it looks smart. +1 Jul 30, 2009 at 20:51
2

You can try out the Expire history by days extension.

2

If you have SQLite you can run this command:

echo 'DELETE FROM moz_historyvisits
WHERE visit_date < strftime("%s", "now", "-5 month") * 1000000; VACUUM;' |
sqlite3 places.sqlite
1

"Today" option means delete history of current calendar day. Not last 24 hours.

For instance, you visit youtube at 23:50 o'clock and now 23:55. Open history -> Today -> you will see youtube. After that you visit superuser at 00:05 o'clock and now 00:15 already. Open history -> Today -> you will see only superuser but open history -> Yesterday -> you will see youtube. So if you chose Clear recent history in Firefox -> Today -> you will delete only superuser but youtube stayed.

1
  • Welcome to Super User! While this may answer the question, it would be a better answer if you could provide some explanation why it does so.
    – DavidPostill
    Jul 2, 2015 at 21:37
1

Here's a script based on @Neville Hillyer's answer that deletes history older than 45 days for every user profile.

#!/bin/sh

PROFILE_DIR="$HOME/Library/Application Support/Firefox/Profiles"
DAYS="45"
MAX_VISIT_DATE="$(date -v-"$DAYS"d "+%s000000")"

find "$PROFILE_DIR" -name places.sqlite | while read -r file; do
    sqlite3 "$file" "DELETE FROM moz_historyvisits WHERE visit_date < $MAX_VISIT_DATE; VACUUM;"
done

You can run it automatically whenever Firefox is quit with Hammerspoon:

local eventTable = {
  [hs.application.watcher.terminated] = function()
    hs.task.new(
      os.getenv("HOME")
      ..
      "/.config/hammerspoon/scripts/firefox_truncate_history"
    , nil):start()
  end
}

appWatcher = hs.application.watcher.new(function(app, event, _)
  if app == "Firefox" then
    local fn = eventTable[event]
    if fn then fn() end
  end
end):start()
0

Just wait 24 hours! or you could close the browser (without saving tabs to cache (bookmark all tabs if required)) and then open it and and see if that worked.

0

The following fast bash script has been working well on my OS X 10.6.8 after I updated /usr/bin/sqlite3. Hopefully it will work on most versions of OS X and Linux.

d=30; # Number of days of history to keep 
find ~ \( -ipath *Mozilla/Firefox*/places.sqlite -or -ipath *Support/Firefox*/places.sqlite \) > ~/.firefox-places; 
x="$(<~/.firefox-places)"; # List of locations of Firefox places.sqlite - may not use 'find' every time in future 
cd "${x%%places.sqlite*}"; # For the time being select only the first places.sqlite location - may change later 
t=$(date -v-"$d"d +%s)000000; # Fast Moz compatible time for 'd' days ago - note the 'multiply' by 1,000,000 
sudo echo "delete from moz_historyvisits where visit_date < $t; vacuum;" | sqlite3 places.sqlite; 

Please don't wrap the above script to improve the display here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .