If you are using Ubuntu 11.04 or newer, you may have noticed that there is no longer an easy way to clear your recently opened items. They could have chosen to do this for different reasons like accessibility or convenience. However, there are some people who simply don’t want their recently opened files to be listed anywhere for whatever reason. Today, I have a couple of ways to do that for you.
Using a Bash script is the easiest way to clear your history. You can have it do nearly anything you could want. Since the point is to clear your recent items, we’ll make a script that will delete the files.
To do this, open gedit and use the following commands to create the script:
#!/bin/bash ## Clear recently accessed files rm -f ~/.recently-used.xbel rm -f ~/.recently-used.xbel.* rm -f ~/.local/share/recently-used.xbel rm -f ~/.local/share/recently-used.xbel.*
This is very simple and removes the recently used items from most GTK-based programs. If you want to go another step and remove thumbnails as well, that’s just one line of code away. Just add:
rm -rf ~/.thumbnails/*
Once you have that done, it should look like this:
Now, just save the file as something like clearhistory.sh. The .sh extension signifies that it is a shell script. To make it executable, right-click on the file and open the “Properties” window. In the Permissions tab, check to box next to where it says “Allow executing file as program“.
Click “Close”, and you’re done.
Placing The Script
If you only want this available to you, on demand, you can either keep it as a file or put the file somewhere safe and keep it as a menu entry. If you want to keep the script itself hidden, create a hidden folder in your home folder like .MyScripts. Be sure to start the folder name with a period to make it hidden by default. Put the file in there.
TIP: You can show/hide hidden folders like these by pressing CTRL+H in Nautilus.
To create a menu entry for it, open your applications menu and find the Main Menu program.
Click on the Category or menu folder you want it to be in on the left, click New Entry and fill in the information. It can be ran either as an application or from the terminal. You can choose this from the first drop-down menu. It does the same thing either way, except you will see a terminal window flash if you select Application in Terminal. You can also give it an icon by clicking on the launcher icon in the upper-left corner of the window.
Now, type in the path to where you put the file. If it is located somewhere in your home folder, you can start the path with “~” like ~/.MyScripts/clearhistory.sh. You can also add a comment to the launcher so you can remember exactly what it does. The comment is displayed as a tooltip where it applies. When you are finished, it should look something like this:
Click OK to close and save the new menu item, and you can close the menu editor. Now, it will be available to you in the application menu. That means you can also add it to your favorites if you want it to be even easier to get to.
Automatically Clear Your History
If you would rather have your history items cleared automatically, place the script in ~/.config/autostart. Everything in this folder will run automatically every time you login. This takes the effort out of the process. However, if you only put it here, it will not be cleared in the middle of any session, so if you want to still be able to do it manually, you can have the menu entry point to the script in the autostart folder.
Another thing to note is that this will only work for the current user. If you have multiple user accounts you want to do this with, you would have to place the file and menu entry in the same way in any other accounts you want it available in. Or, you can have it done automatically at shutdown, which can easily clear the history system-wide.
System-wide On Shutdown
This part is a little more involved, but it can also simplify the process if you want to use it on multiple accounts. To start, open the Run command by pressing ALT+F2 and type:
gksudo gedit /etc/init.d/clearallhistory.sh
This will open gedit as root so you can save the file to the system directory. You can also name the file something other than clearallhistory.sh if you like, but remember to keep the .sh extension. You can copy the code from the original script and change it from there by changing ~/ to /home/*/ like this:
#!/bin/bash ## Clear recently accessed files and thumbnails rm -f /home/*/.recently-used.xbel rm -f /home/*/.recently-used.xbel.* rm -f /home/*/.local/share/recently-used.xbel rm -f /home/*/.local/share/recently-used.xbel.* rm -rf /home/*/.thumbnails/*
The asterisk (*) is used as a wildcard, so it will follow all paths in the /home/ folder to remove the history files. Once you have the code in place, save and close.
Now, you need to open the terminal to do the rest of this part. First, you need to make the script executable. Since it’s in the system directory, you can’t do it as a standard user, so that is why the terminal is being used here. Type the command:
sudo chmod +x /etc/init.d/clearallhistory.sh
This will set the script as executable and you can continue. Now you need to link it to the proper places by using these commands:
sudo ln -sf /etc/init.d/clearallhistory.sh /etc/rc0.d/S10clearallhistory.sh sudo ln -sf /etc/init.d/clearallhistory.sh /etc/rc6.d/S10clearallhistory.sh
This puts a link to the file in the folders of things that are automatically ran on shutdown and restart. You will notice that in the rc0.d and rc6.d folders, the file name starts with “S10″. This is because the scripts in this folder are ran in order of their filenames. The lower the number, the earlier it is ran. By default, Ubuntu ships with scripts starting at S20 in these folders.
If you decide to edit this script in the future, you will only need to do so to /etc/init.d/clearallhistory.sh because the other two locations are only linked to this one.
Specific Users On Shutdown
If you don’t want the history cleared from all accounts on shutdown, you will still use the above process, but you will need to change the script a bit. Instead of using the * wildcard, you will need to create a new command for each user you want cleaned. Each command should look something like this:
rm -f /home/josh/.recently-used.xbel rm -f /home/amanda/.recently-used.xbel
This should be repeated for every command you want ran on each account you want it ran on.
Whatever your reason for wanting a clean history on your computer, this will make it work for you. If you followed the entire process, you should now have the script in the autostart folder in your profile, in the application menu, and in the shutdown/restart scripts folders.
Does this work for you, or do you want another method? Maybe you already have another method. Let us know what you have to say in the comments.