tags:

views:

195

answers:

6

Whenever I edit files on emacs, it seems a temporary file is created with the same name with ~ appended to it. Does anyone know an quick/easy way to delete all of these files in the working directory?

+5  A: 
rm -rf *~ 
S.Mark
this does not handle subdirectories
dzen
You can invoke the above command from within Emacs by typing M-! first.
offby1
+5  A: 
find . -name '*~' -exec rm {} \;

EDIT: Huh ... while this works, I posted it thinking rm *~ would cause the shell to interpolate ~ into the user's home dir. It doesn't, at least with the version of bash on this machine - YMMV, of course.

Brian Roach
+5  A: 

You can just

rm *\~

More usefully, you can change the emacs backup directory so all those files are stored in a common location, by adding this to your .emacs:

'(backup-directory-alist (quote (("." . "/common/backup/path"))))

There are other options you can fiddle with

Michael Mrozek
+1 for mentioning a good practice on storing backup files.
Török Gábor
+2  A: 

From the working directory:

$ rm *~

From everywhere:

$ cd; find . -name '*~' | xargs rm -f

From within emacs, using dired.

C-x C-f . RET ~ x y e s RET

You can suppress backup file creation permanently by adding the following line to your ~/.emacs

(setq make-backup-files nil)

I don't recommend this last one, as emacs's backup files have saved me many times over the years.

Dale Hagglund
+1 for the dired way.
Török Gábor
+1  A: 

You can open the directory in emacs, flag all backup file with ~ then delete them with x

Rémi
+5  A: 

While all the others answers here correctly explain how to remove the files, you ought to understand what's going on. Those files ending in ~ are backup files, automatically created by Emacs. They can be useful sometimes. If you're annoyed by the files and want to delete them every time, then you either

(1). prevent the creation of backup files:

(setq make-backup-files nil)

or

(2). Have it save the backup files in some other directory, where they won't bother you unless you go looking for them. I have the following in my .emacs:

(setq backup-directory-alist '(("." . "~/.emacs.d/backup"))
  backup-by-copying t    ; Don't delink hardlinks
  version-control t      ; Use version numbers on backups
  delete-old-versions t  ; Automatically delete excess backups
  kept-new-versions 20   ; how many of the newest versions to keep
  kept-old-versions 5    ; and how many of the old
  )

(Only the first line is crucial.) To see documentation about backup-directory-alist, type C-h v backup-directory-alist.

ShreevatsaR