Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Using Firefox. I would like to get rid of "obsolete" cookies. By "obsolete" I mean cookies which have not been accessed by any website in the last x days.

I have searched high and low but I have not found how to do that. What I have found is, among others:

  • restrict the lifetime of all cookies (about:config -> network.cookie.lifetimePolicy).
  • whitelist or blacklist domains (firefox preferences -> privacy -> cookie exceptions).
  • delete all cookies from the last x hours (firefox history -> clear recent history).

None of that is what I want.

I want to delete all cookies which have not been accessed by any website in the last x days.

share|improve this question
1  
Most likely, an extension is needed for this. –  Hello71 Jan 4 '12 at 16:12
    
Not sure if this accomplishes what you want, but I have Firefox to not automatically accept cookies, and instead am prompted when cookies try to install. In the prompt dialog box, I choose to store the cookie as a "session" cookie rather than a "standard" cookie. –  sawdust Jan 4 '12 at 22:50
add comment

2 Answers

up vote 0 down vote accepted

I did some research.

  1. Cookies are stored in the cookies.sqlite file in the firefox profile directory.
  2. The file is a sqlite database.
  3. The timestamp of the last access is stored in the lastAccessed column.
  4. The format of lastAccessed is some PRTime format, which is basically the unix epoch time with microseconds.

The following query will list every cookie which has not been accessed in the last 14 days.

select host, name from moz_cookies
where lastaccessed < strftime('%s000000', 'now', '-14 days')
order by lastaccessed;

I just learned some SQL for this, so it might very well be that this query can be done better.

The following query will delete all those cookies.

delete from moz_cookies
where lastaccessed < strftime('%s000000', 'now', '-14 days');

Here is a quick and dirty shell script which does the job. You will need the sqlite3 command installed on your system.

#!/bin/sh

DAYS="14"

TABLE="moz_cookies"
LASTACCESSED="lastaccessed"

SELECT="select host, name"
DELETE="delete"
FROM="from $TABLE"
OBSOLETE="strftime('%s000000', 'now', '-$DAYS days')"
WHERE="where $LASTACCESSED < $OBSOLETE"
ORDER="order by $LASTACCESSED"

SELECTQUERY=".mode tabs\n$SELECT $FROM $WHERE $ORDER;"
DELETEQUERY="$DELETE $FROM $WHERE;"

echo $DELETEQUERY | sqlite3 cookies.sqlite
share|improve this answer
add comment

The Cookie Time extension can be configured to automatically delete cookies that haven't been used for a specified time (expired). It also has a separate setting to force expire / delete all cookies that are beyond a specified age.

Cookie Time configuration screenshot

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.