Mark Finch - Plan Design Develop Repeat

It’s a curse we love ‘em and hate ‘em.  Temporary backup files can be real life savers.  The problem often is that by enabling them on every application you end up with lots of extraneous files littering your hard drive.  One application is a particularly bad litterer; Gedit!

To get rid of the existing temporary files you can use the following command:

find . -name '*~' -print0 | xargs -0 /bin/rm -f

What this does is recursively find all files with the regular expression ‘*~’ then deletes them by printing them to a buffer and passing it to the rm command.

In my .bashrc file I added an alias to make it easy to remove these litter bugs in the future.

Open your .bashrc file in your favorite editor (it’s a hidden file in your home directory) and towards the bottom there should be a section with a number of alias commands.  At the end of the list add the following:

alias rm~='find . -name '*~' -print0 | xargs -0 /bin/rm -f'

Then save and from now on you can simple type rm~ every time you need to get rid of those temporary files. 

NOTE: This command will recursively search the path from your current location down the tree, so if you are at the root it will delete any file with a ~ at the end on the drive.  **SO IT IS POSSIBLE IT COULD DELETE THINGS YOU WANT TO KEEP!! USE WITH CAUTION!**  I use it for cleaning up my source trees before a commit.

NOTE2: You can turn these temporary files off in Gedit -> Edit -> Preferences and untick “Create Backup Copy of File Before Saving” on the Editor tab.

Gedit Preferences

blog comments powered by Disqus