I'm new to Unix. Whenever I exit the Emacs editor after editing a file say foo.c by pressing CTRL+X+C, I see a new file automatically created called
~foo.c. What is it and why is it automatically created?
Please help me... Thank you!
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
You can disable backups, but that's a bad idea for obvious reasons. If you dislike seeing them alongside the current file, you can tell Emacs to store them somewhere else.
I use the following in my ~/.emacs.d/init.el file:
;; Write backups to ~/.emacs.d/backup/ (setq backup-directory-alist '(("." . "~/.emacs.d/backup")) backup-by-copying t ; Don't de-link hard links 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
They are backup files, so you can roll back to the previous version of the file if you need to.
If they bother you, just clean them up periodically with:
find . -name "*~" -depth 1 -delete
This will clear all the
*~ files found in the current directory, remove
-depth 1 if you want to clean them recursively in all sub-directories too, of course, any file ending with
~ will get killed, so apply caution.
Of course, you can tell Emacs to stop making them if you want, just add this line to your
(setq make-backup-files nil) ;; do not make backup files
What you're seeing is a temporary file created when editing the file.
The proper way to save and exit in emacs is Ctrl-x Ctrl-c (I don't believe you let go of Ctrl in between the x and c) Please see here for more emacs help.
When you save a file in Emacs, it automatically creates a backup file (what the file looked like before editing) with the “~” prefix.
If you don’t want this, see: http://www.rpi.edu/dept/acs/rpinfo/common/Computing/Consulting/Software/Emacs/Hints/backup.html