4

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,

Shuzheng
  • 425
  • Linking to that post since http://askubuntu.com/questions/154474/what-are-the-files-created-when-i-edit-something-and-can-i-delete-them?lq=1 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 08:51
  • vim does it too by default – Thomas Jul 11 '15 at 09:22
  • Ubuntu's default editor gedit also does this, and you can turn it off in its settings. – Paddy Landau Jul 14 '15 at 08:33

3 Answers3

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.

Daniel Griscom
  • 272
  • 1
  • 10
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.