Disabling GNOME’s recently-used file list, the better way
Updated May 14th, 2020
I never liked the idea of recently-used file lists. I usually know what file I want to use and where it is, so for me there’s no real need for them. Even if I did find them useful, they’re constantly rearranging themselves, so actually locating the one file I want to use in an ever-shifting list of ten or twenty isn’t easy.
It’s also a privacy concern. I’m usually the only one to use my computer, so I only have one user account. I don’t mind if friends or family use it, and they often do to quickly check email or watch a movie while I’m away. Do I really want them seeing what files I’ve opened? Do they really want me to see what files they’ve opened?
In any case, I disable GNOME’s recently-used file list as soon as I set up my computer.
How to disable recently-used files
In the past, it was a little complicated to disable recently-used files. Nowadays, it’s as simple as doing this:
gsettings set org.gnome.desktop.privacy remember-recent-files false
That’s all there is to it. The older ways are preserved below, for posterity; but you probably don’t need to read any further.
Old method #1
This was the first method I found to disable the recently-used file list. It’s definitely easy to do. Run these two commands in the terminal:
echo "" > ~/.local/share/recently-used.xbel sudo chattr +i ~/.local/share/recently-used.xbel
The first command clears out the recently-used file list. The second command instructs the filesystem to make the recently-used file list “immutable” (hence the “+i”), which means nobody—including programs—can read, write, or delete the file.
To re-enable the recently-used file list, just remove the immutable attribute:
sudo chattr -i ~/.local/share/recently-used.xbel
This method is easy and works pretty well… except, that is, until you launch a GTK application from the terminal. Say, for example, I’ve got my terminal open in a Git repo. I want to launch my GTK Git program, gitg. It launches, I do my thing, and I close it… to find my terminal a mess!
What happened? Well, since GTK can’t touch the recently-used file, it spits out a bunch of warnings and errors to the terminal. That screenshot is me just opening and closing gitg. If you ran, say, Gedit and edited a bunch of files, you’d get way more errors in your terminal.
All that unneeded output messes up my terminal workflow. How do we get around it, while still disabling the recently-used file list?
Old method #2
Lucky for us, in GNOME 3 there’s a handy hidden setting you can write to disable the recently-used file list. If you’re on GNOME 2, skip this section and go to the next one, your life won’t be as easy.
Put the following in ~/.config/gtk-3.0/settings.ini (create the file if it doesn’t exist):
[Settings] gtk-recent-files-max-age=0 gtk-recent-files-limit=0
Then, remove the file holding recently-used data:
You can do everything at once with these terminal commands:
mkdir -p ~/.config/gtk-3.0 echo -e "[Settings]\ngtk-recent-files-max-age=0\ngtk-recent-files-limit=0" > ~/.config/gtk-3.0/settings.ini rm ~/.local/share/recently-used.xbel
And there we go! No more error messages in the terminal. That’s the best way to disable the list in GNOME 3.
Old method #3
As far as I know, GNOME 2 doesn’t have a convenient setting you can write to disable the list. So we’ll have to do something a little more complex.
If we approach the problem differently, we can come up with a better way to disable the list. Our old method simply made the file not-writable. What if we could simply monitor the file for changes, and empty the file whenever it changed?
That would stop GTK from complaining, because it can successfuly write to the file. It would also effectively disable the list, because it would always be empty.
We can achieve this using a special tool called inotifywait. Inotifywait is a small program that monitors the state of a file you specify and lets you know when it changes. Let’s create a script that uses this tool to monitor and empty the recently-used file list.
First, install the inotify-tools package.
sudo apt-get install inotify-tools
Next, create this bash script:
#!/bin/bash file=$HOME/.local/share/recently-used.xbel echo "" > "$file" while inotifywait -e modify -e delete_self "$file" 2> /dev/null; do echo "" > "$file" done
You can create it in ~/monitor-recently-used by running this in your terminal:
echo -e "#\!/bin/bash\n\nfile=\$HOME/.local/share/recently-used.xbel\necho \"\" > \"\$file\"\nwhile inotifywait -e modify -e delete_self \"\$file\" 2> /dev/null; do\n\techo \"\" > \"\$file\"\ndone" > ~/monitor-recently-used
Make the script executable:
chmod +x ~/monitor-recently-used
Finally, add it to GNOME’s startup sequence:
mkdir -p ~/.config/autostart/ echo -e "[Desktop Entry]\nType=Application\nExec=~/monitor-recently-used\nX-GNOME-Autostart-enabled=true\nName=monitor-recently-used" > ~/.config/autostart/monitor-recently-used.desktop
All of this is assuming you’re placing the script in your home directory. You’ll probably want to put it somewhere else. Once you log out and log in again, it should be working!
This script uses use inotifywait to monitor the recently-used file. If the file is modified or deleted (GNOME actually seems to delete and recreate the file every time instead of just modifying it), we echo an empty string into the file to clear it out. Simple!
Now you can enjoy a disabled recently-used file list, and no garbage output when launching GTK apps from the terminal.