I originally had three files: makefile
, readme.txt
, and hashtable.c
in my directory, where I am writing my code in emacs. I noticed that some new files: #hashtable.c#
, #readme.txt#
, hashtable.c~
, and makefile~
have been created. I was wondering what these files were. Are these important, and if not, how do I tell emacs to stop making them? I'm also curious why readme.txt
doesn't get a tilde file and makefile
doesn't get a sharp file.

- 97,681
- 90
- 411
- 885

- 5,982
- 14
- 47
- 87
-
Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Sep 09 '18 at 06:27
4 Answers
The file with the ~
is a backup file that automatically gets created when you save a file. The #
readme.txt#
is the file being currently edited/in use (i.e., the autosave version). That will usually go away (unlike the ~
file) when you exit emacs normally (if it crashes or gets killed the # files may stay around).
You might find this page about emacs backup files of interest, and this SO question: How do I control how Emacs makes backup files?
You can prevent backup files from being created with this:
(setq make-backup-files nil)
-
This makes sense. I was confused because I used `kill -9 #####` to get rid of emacs, but I guess closing it that way didn't delete the temporary files. – Andrew Latham Aug 20 '12 at 03:07
-
4Never, ever, ever use `kill -9` unless you have verified that the process cannot be killed by other means. Usually, try with just `kill`, then maybe after a few seconds `kill -2`. Emacs has a keystroke for quitting it, though; `C-x C-c`. – tripleee Aug 20 '12 at 04:00
-
2Andrew: They're not "temporary files" (which would live in the OS's tmp directory in any case). The presence of the autosave files tells you that there were unsaved changes to those files when you forceably killed Emacs. Don't disable backups, either (you can configure Emacs to put them somewhere else if you prefer, but *disabling* backups isn't a good idea for hopefully-obvious reasons). – phils Aug 20 '12 at 05:16
-
5For other total n00bs like myself, this goes in ~/.emacs, which may or may not already exist for you. – mikermcneil Jan 04 '13 at 06:27
I recommend installing no-littering
. It automatically puts backup files (file~
) in ~/.emacs.d/var/backup/
. It doesn't do anything about autosaves (#file#
), but there is a note about putting those files in a specified directory in the README:
(setq auto-save-file-name-transforms
`((".*" ,(no-littering-expand-var-file-name "auto-save/") t)))
Neither of these things actually prevents Emacs from creating these files, but I'm assuming most people actually want these files (in case of a crash), but don't want them strewn all over the filesystem.

- 9,237
- 3
- 29
- 34
For #files# you have to do rm "#file#"
from the terminal, because rm #file#
doesn't work.
For ~file you can simply digit rm ~file
.

- 873
- 1
- 15
- 40
Maybe you could try:
find . -name \\#*\\# | xargs rm
Warning: this will remove those files matching in subdirectories.

- 805
- 1
- 12
- 23

- 1
-
I would add `-type f` to the `find` command, just to be sure we don't delete directories. Then we can also replace the `| xargx rm` by `-delete`, which `find` supports: `find -type f -name '#*#' -delete` – adentinger Feb 16 '23 at 14:10