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?

1

3 Answers 3

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.

1
  • might use -delete instead of -exec, it's much faster because it doesn't spawn new process.
    – Xah Lee
    Commented Sep 25, 2014 at 12:42
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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.