9

When editing files, some foo.bar~ backups appear (files ending with a tilde ~). How can I control their creations, and is it possible to ask for a recursive bulk deletion of all files from a specific directory and all it's sub directories?

Drew
  • 75,699
  • 9
  • 109
  • 225
smonff
  • 1,575
  • 1
  • 15
  • 20
  • There are really 2 questions here; "How can I control their creations" seems like a partial duplicate of http://emacs.stackexchange.com/questions/33/put-all-backups-into-one-backup-folder – shosti Sep 23 '14 at 22:37

3 Answers3

8

You can make all backup files to go a directory with

(setq backup-directory-alist `(("." . "~/.emacs.bak")))

and turn it off completely with

(setq make-backup-files nil)

although nobody will recommend that.

Making backups for only some projects is not easy: you'll have to flip that variable in various hooks.

Finally, asking for bulk deletion is exactly equivalent to:

find . -name '*~' -exec rm {} \;

so you might be better of doing that in the shell.

artagnon
  • 2,237
  • 1
  • 15
  • 17
4

dired makes it easy to delete all the backup files in a directory--from dired, just type ~ to mark backup files for deletion and x to execute the deletion.

shosti
  • 5,048
  • 26
  • 33
3

From https://www.gnu.org/software/emacs/manual/html_node/emacs/Backup-Names.html#Backup-Names

You can customize the variable backup-directory-alist to specify that files matching certain patterns should be backed up in specific directories. This variable applies to both single and numbered backups. A typical use is to add an element ("." . dir) to make all backups in the directory with absolute name dir; Emacs modifies the backup file names to avoid clashes between files with the same names originating in different directories. Alternatively, adding, ("." . ".~") would make backups in the invisible subdirectory .~ of the original file's directory. Emacs creates the directory, if necessary, to make the backup.

If you define the variable make-backup-file-name-function to a suitable Lisp function, that overrides the usual way Emacs constructs backup file names.

You can also set EMACS to keep numbered backups and only keep a given number of backups, although this may be worse than just a single backup for each file. See https://www.gnu.org/software/emacs/manual/html_node/emacs/Backup-Deletion.html

M Smith
  • 279
  • 1
  • 7