A script to clean up Okular metadata
Tagged:  •    •  

Okular, the PDF viewer for KDE, stores some metadata for the documents you have opened in the past. For example, it stores the position within the document whenever you close it, or the annotations you've made while auditing a document.

However, this metadata is not cleaned up automatically. This results in many files in the Okular data folder about files you have removed a long time ago. The following little script cleans all metadata of non-existent files for you. It is recommended to put this in a weekly cron job, so you never have to think of it again.

#!/bin/bash

# (C) 2009 Bram Schoenmakers <bramschoenmakers@kde.nl>

cd "$(kde4-config --localprefix)/share/apps/okular/docdata"

for A in *.xml; do
        B=`sed -ne 's/^<documentInfo .*url="\(.\+\)".*>$/\1/p' "$A"`
        [ -f "$B" ] || rm -f "$A"
done

Trying to see what the script does

I don't understand, ¿is not enough...
rm $(kde4-config --localprefix)/share/apps/okular/docdata/*.xml
?

My script only removes

My script only removes metadata from files which don't exist anymore on the filesystem. Your version simply removes all metadata.