Emacs: Turn Off Backup
How to make emacs stop creating “backup~” files or “#autosave#” files?
Put the following in your emacs init file.
(setq make-backup-files nil) ; stop creating backup~ files (setq auto-save-default nil) ; stop creating #autosave# files
How to stop emacs from creating .#lock file links?
emacs backup is so annoying. even when you have it off (setq auto-save-default nil) , it still creates temp # files. which crashes script that traverse dir.
Solution:
(setq create-lockfiles nil)
This will completely stop emacs from creating temoporary symbolic link file named “#something”.
(disable lock file may be a problem if you have situations where a file is being edited by different people or instances of emacs.)
2018-10-12 thanks to Dale Hagglund https://twitter.com/DaleHagglund/status/1050786629844004865 for create-lockfiles
How to set emacs so that all backups are placed in one place?
Put the following in your emacs init:
;; backup in one place. flat, no tree structure (setq backup-directory-alist '(("" . "~/.emacs.d/backup")))
This will create backup files flat in the given dir, and the backup file names will have “!” characters in place of the directory separator.
For example:
- file
/A/B/web/xyz/myfile.txt - backup root dir
/A/B/.emacs.d/backup - backup at
/A/B/.emacs.d/backup/A!B!web!emacs!myfile.txt~
If you use long file names or many nested dirs, this scheme will reach file name length limit quickly. (Mac and Windows allow 255 chars for file name.)
How to set emacs so backups in one place with tree structure?
Put the following in your emacs init file:
;; make backup to a designated dir, mirroring the full path (defun my-backup-file-name (fpath) "Return a new file path of a given file path. If the new path's directories does not exist, create them." (let* ( (backupRootDir "~/.emacs.d/backup/") (filePath (replace-regexp-in-string "[A-Za-z]:" "" fpath )) ; remove Windows driver letter in path, for example, “C:” (backupFilePath (replace-regexp-in-string "//" "/" (concat backupRootDir filePath "~") )) ) (make-directory (file-name-directory backupFilePath) (file-name-directory backupFilePath)) backupFilePath ) ) (setq make-backup-file-name-function 'my-backup-file-name)
The above will mirror tree structure to the backup dir.
For example:
- file
/A/B/web/xyz/myfile.txt - backup root dir
/A/B/.emacs.d/backup/ - backup at
/A/B/.emacs.d/backup/A/B/web/xyz/myfile.txt~
(info "(elisp) Backup Files") (info "(emacs) Backup")
How to Delete Emacs Backup Files
To delete all backup files in current dir:
- Alt+x
dired. dired-flag-backup-files【~】 → mark all backup files for deletion.dired-do-flagged-delete【x】 → (execute) delete files flagged for deletion.
[see Emacs: File Manager, dired]
Or, you can use the linux shell command:
# delete all file whose name end in ~. All subdir too. find . -name "*~" -delete
You can setup a abbrev to quickly type the shell line.
[see Emacs: Abbrev Mode]
Even more efficient is to set a command that lets you pick a shell command. See: Emacs: Interactive Abbrev.
Backup on Demand
Emacs Customization
- Emacs init file
- Install Packages
- Install Package Manually
- Define Keys
- M-x customize
- What's Major Mode?
- What's Minor Mode?
- Set File to Open in a Major Mode
- Organize Init File
- Byte Compile Elisp
- What's Hook?
- Environment Variables in Emacs
- Set Default Window Size
- Font Setup
- Set Color Theme
- Turn Off Auto Backup; Set Backups into a Directory; How to Delete Backup Files
- Elisp: Determine OS, Emacs Version, Machine Host Name
- Elisp: Check If a {function, variable, feature} is Defined/Loaded
If you have a question, put $5 at patreon and message me.