4

This question already has an answer here:

Why does Ubuntu create a file ending in ~ for every file I create with a text editor ?

Creating a file with a text editor like GNU Emacs, say myfile, another file called myfile~ is also created. Why is this superfluous file created ? Using cat on it displays nothing.

Thanks,

marked as duplicate by muru, Eric Carvalho, karel, A.B., Maythux Jul 14 '15 at 10:15

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Linking to that post since askubuntu.com/questions/154474/… was closed as an exact dup. – muru Jul 10 '15 at 23:03
  • 3
    Note: this is nothing to do with the OS, only with the application. For example kate by default does this too, and you can install it on Windows too. You can simply go to its settings and tell him to avoid creating backups. – Bakuriu Jul 11 '15 at 8:51
  • vim does it too by default – Thomas Jul 11 '15 at 9:22
  • Ubuntu's default editor gedit also does this, and you can turn it off in its settings. – Paddy Landau Jul 14 '15 at 8:33
15

Emacs' default mode is to create a backup file with a "~" suffix every time you edit and save a file. You can disable this by creating a .emacs file in your home directory and setting an option inside it. This happens with Emacs on all platforms. Other editors may do the same under Ubuntu, but it has nothing to do with Ubuntu itself.

6

It's a backup file that contains the file's content from before saving and will be created every time you save the file.

  • 1
    Thank you very much, I see now that this is the case for my files. Does this apply to every file in Ubuntu, or is it specific to GNU Emacs ? – Shuzheng Jul 10 '15 at 19:23
  • @NicolasLykkeIversen I think it's an emacs thing. For example if I open a file in nano and make edits, I don't get the ~ file – Mitch Jul 10 '15 at 20:03
  • Some other programs do that, too. Files with names ending in ~ are usually backup files. Some programs, like Nautilus, have an option to hide backup files, which means they don't display those files. – Florian Diesch Jul 10 '15 at 20:04
6

It's emacs(and xemacsand jed) -- not Ubuntu -- that creates those files. It's a copy of the previous version of the file your editing, ie. the file as it was before you made changes and used "save" to save them. I admit it's often a bother, but it's certainly useful if you've make changes you later regret.

It can be turned off manually -- and you can turn it off by default in the .emacsrc file.

Personally I run a cron-job that removes back-ups that hasn't been accessed for more than a week.

emacs also make files called something "#filename#" and ".#filename#". This file contained unsaved changes -- ie. things you've done since last save. The file is periodically updated as you edit a file. If emacs (or your computer) crashes, you'll be asked to continue with the "recovered buffer" if you try to edit the file again. (These files I also periodically "cron-away".)

My advice, keep letting emacs make back-ups... sooner or later you'll regret it if you don't.

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