OK, I was looking around the ~/.nautilus directories yesterday (poking round at what configuration files are in place, as I was updating an old script of mine, and went on a hunt to find easier ways to obtain information on things, such as mounted hard drives, etc, etc...)
All of a sudden I came across this folder:
~/.nautilus/metafiles/
To which there are a few xml files of certain directories.
So I investigated them, and found a rather large file...
$ wc -l file:%2F%2F%2Fhome%2Fiain%2FDesktop.xml
2 file:%2F%2F%2Fhome%2Fiain%2FDesktop.xml
OK, two lines... seems tiny, but:
$ wc -c file:%2F%2F%2Fhome%2Fiain%2FDesktop.xml
9937 file:%2F%2F%2Fhome%2Fiain%2FDesktop.xml
But for two lines... It has nearly ten thousand characters in it...
So I checked it out, and it turns out that nautilus keeps records of every file that was ever on your desktop.
I don't know about some, but I'd rather not have data of files that don't exist anymore stored in configuration files, so I wrote a script to clean the crud (removes details of files that no longer exist):
#!/usr/bin/perl
# clean.pl
use warnings;
use strict;
use XML::Parser;
use File::stat;
my($path) = "$ENV{HOME}/.nautilus/metafiles/";
my($xmlout) = '';
&listdir;
# Emulate ls
sub listdir {
local *XML;
if(!opendir(XML, $path)) {
print 'Error: cannot access '.$path."\n";
exit 1;
}
for (readdir(XML)) { # Match all files for home folder.
if(/^file:%2F%2F%2Fhome/) { # Delete xml files for hidden files/folders, and subdirectories of the top home folders.
if(/(%2F\..*)|(home%2F\w+%2F\w+(%2F.*)+)$/) {
unlink($path.$_);
next;
} # Skip if file checks out and is not for the Desktop.xml config.
elsif(!/Desktop\.xml$/) {
next;
} # Clean out the Desktop.xml config.
$xmlout = "<?xml version=\"1.0\"?>\n";
&parse($path.$_);
open(FILE, '>', $path.$_);
print FILE $xmlout;
close FILE;
next;
} # Else delete if filename is not /^x-nautilus/
elsif(!/^x-nautilus/) {
unlink($path.$_);
next;
}
}
}
# Parse the input file.
sub parse {
my($file) = @_;
my($parser) = XML::Parser->new();
$parser->setHandlers(
Start => \&beginTag,
End => \&endTag
);
$parser->parsefile($file);
}
# Start Element
sub beginTag {
my($parseinst, $element, %attrs) = @_;
if($element eq 'directory') {
$xmlout .= "<$element>";
} # If the file no longer exists in the Desktop folder, don't add it in to the new file buffer.
elsif($element eq 'file') {
my($name) = $attrs{name};
$name=~s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
if( -e "$ENV{HOME}/Desktop/$name") {
$xmlout .= "<$element name=\"$attrs{name}\" ";
$xmlout .= "timestamp=\"$attrs{timestamp}\" ";
$xmlout .= "icon_position=\"$attrs{icon_position}\"/>";
}
}
}
# End Element
sub endTag {
my($parseinst, $element) = @_;
$xmlout .= "</$element>" if($element eq 'directory');
}
And the results:
$ wc -l %2F%2F%2Fhome%2Fiain%2FDesktop.xml
2 file:%2F%2F%2Fhome%2Fiain%2FDesktop.xml
$ wc -c file:%2F%2F%2Fhome%2Fiain%2FDesktop.xml
412 file:%2F%2F%2Fhome%2Fiain%2FDesktop.xml
Better?
Regards Iain