jump to navigation

Tilde (backup file) cleanup January 26, 2006

Posted by Carthik in snippets, ubuntu.
trackback

In response to my request for tips from users, a few have written in with their favourite tips. I will be posting them here, in the order received, one or more per day.

First, Clifton Snyder has a tip to share with everyone.

Several text editors these days – Emacs, jEdit, et al – leave behind pesky tilde-files after you’ve edited/saved them. This can lead to a cluttered mess of extraneous backup files in different directories. (.bashrc~, .bash_profile~, .fluxbox/menu~, etc.). Thus, one of the smallest – but most useful – snippets that I use is the following alias:

alias emacs-clean='find . -name "*~" -exec rm {} \; -or -name ".*~" -exec rm {} \;'

This will find all files in $PWD and below that have a tilde (~) appended to them and send them to The Great Bit-Bucket Beyond.

I have the following to add:
An alias is something you add to your ~/.bashrc file. Once you add that line to your .bashrc file, typing “emacs-clean” on the command line will execute the action.

The tilde files are automatic backup files of the last version created by the text editors. You can turn off this automatic creation by editing the preferences of the text editor you use.

If you don’t want an alias, and just want to run this once (or every once in a while), execute the following command:
$find . -name "*~" -exec rm {} \; -or -name ".*~" -exec rm {} \;

Comments»

1. Andy C - January 27, 2006

Careful. Emacs backup files have saved my skin on more than one occasion. If you don’t want (or think you need) them, don’t generate them in the first place.

2. random guy - January 28, 2006

is this blog using ajax

3. Kyle - January 31, 2006

Rather than deleting your backups every once and a while, why not just change your editors behavior. I include the following in my .emacs file:

;; create a backup file directory
(defun make-backup-file-name (file)
(concat “~/.emacs.backups/” (file-name-nondirectory file) “~”))

So when I edit a file, the backup is created in the ~/.emacs.backups directory rather than the current directory.

4. Marc - February 10, 2006

I agree with Kyle. Here’s the vim equivalent:

set backupdir=~/backups ” Don’t store backups in the current directory

5. Braden - June 1, 2006

Scary running a wildcarded rm, but it worked perfectly. Many thanks.

(Also, thanks to the commenters. Putting it in a backup directory’s a great idea.)

6. henok - August 4, 2006

so how can I disable tilde file creation in Vim?

7. JB - September 22, 2006

:set nobackup

8. Beulbek » Emacs, PHP and the tilde - July 20, 2007

[…] found this trick at Ubuntu Blog where a guy called Kyle added a comment about an auto-cleanup script. It’s about editing your […]

9. Ryan - December 13, 2007

Thanks Marc, your line works like a charm.

10. Jay - December 14, 2007

Another option that’s nice on Windows is to move the tilde to the beginning of the file name. That way you won’t accidentally pick the wrong file, and your file types (and associtions in Explorer) aren’t hosed. Plus, they should stick together when a directory is sorted alphabetically.

So instead of the infuriating “file.txt~”, I’d have “~file.txt”, which still goes to emacs when double-clicked.

That way my line looks like

(defun make-backup-file-name (file)
(concat “~” (file-name-nondirectory file) ))

I just tried this for the first time a few minutes ago, so take care.

11. Aviv - March 27, 2010

With gedit, you can just go to Edit -> Preferences and unselect “Create a backup copy of files before saving”.

12. porno sikiş - September 27, 2010

so how can I disable tilde file creation in Vim?

13. sex sikiş - September 28, 2010

So when I edit a file, the backup is created in the ~/.emacs.backups directory rather than the current directory.

14. lolwut - October 7, 2010

Does anyone know how I can assign a backup directory for jed? Or disable ~ file generation completely? I tried to mess around a bit with my .jedrc but couldnt get it to work.

15. soaked - June 3, 2015

It’s awesome to go to see this web site and reading the views of all friends
on the topic of this article, while I am also keen of getting know-how.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: