Emacs: Turn Off Backup

By Xah Lee. Date: . Last updated: .

disable emacs's automatic backup~ file

Put this code in your emacs init file:

(setq make-backup-files nil)

disable emacs's #autosave#

Emacs: Auto Save

set emacs so that all backups are placed into one backup folder

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:

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.)

set emacs backups in one dir 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:

(info "(elisp) Backup Files") (info "(emacs) Backup")

stop emacs's backup changing the file's creation date of the original file

Put this code in your emacs init file:

(setq backup-by-copying t)

Explanation: when emacs does a backup, by default it renames the original file into the backup file name, then create a new file and insert new file content into it. This effectively destroys the creation date of your file. (If a file is created in 2001, and you modified it today, the file's creation date will become today. Note: unixes (including Linux and BSD) do not record file creation date, so this doesn't matter. (ctime is not creation date.) Microsoft Windows and Mac OS X do record file creation date.).

How to Delete Emacs Backup Files

To delete all backup files in current dir:

  1. Alt+x dired.
  2. dired-flag-backup-files~】 → mark all backup files for deletion.
  3. dired-do-flagged-deletex】 → (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: Backup Current File

Emacs Customization

  1. Emacs init file
  2. What's Major Mode
  3. What's Minor Mode
  4. M-x customize
  5. Organize Init File
  6. Byte Compile Elisp
  7. What's Hook
  8. Avoid Lambda in Hook
  9. Environment Variables in Emacs
  10. Check OS, Version, Host Name
  11. Check Defined/Loaded

packages

  1. Install Packages
  2. Install Package Manually

text editing

  1. Define Keys
  2. Set Mouse Buttons
  3. Tabs, Space, Indentation Setup
  4. auto bracket pair
  5. Copy/Cut Line If No Selection
  6. Isearch space for - _
  7. Ido Completion
  8. Icomplete Completion
  9. Move Cursor by camelCase
  10. Stop Cursor Going into Minibuffer Prompt
  11. Sync Clipboard with Linux X11

file

  1. Default Major Mode
  2. Auto Backup Off
  3. Auto Save
  4. Restore Opened Files
  5. Save Cursor Position
  6. Dired Customization
  7. Open Recently Opened
  8. Open Last Closed File

appearance

  1. Show Line Numbers
  2. Show Cursor Position
  3. Visual Line Mode, Wrap Lines
  4. High Light Current Line
  5. Make Whitespaces Visible
  6. Set Default Window Size
  7. Font Setup
  8. Line Spacing
  9. Set Color Theme
  10. Highlight Paren
  11. Show lambda as λ
  12. Color CSS Hex Code

misc

  1. Default Browser
  2. Misc Init Tips

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs

Emacs

Emacs Lisp

Misc