2

Whenever I open a LibreOffice document, LibreOffice creates a lock file along the original file. This file has a naming schema like the following:

.~lock.MyDocument.odt# 

Is this a LibreOffice specific naming pattern? Is it common on Linux? Why do LibreOffice use exactly that pattern? Why did they choose those specific extra characters?

  • 1
    It is not a Linux thing (Linux is just a kernel). It may be a Unix, Gnu thing. – ctrl-alt-delor Apr 27 at 9:17
2

The leading dot hides the file from some directory listings. This comes from historical behavior of the ls command, which lead many programs to use leading dots to denote files that aren't meant to be visible in directory listings, which in turn lead to many file managers hiding such files by default.

The tilde is an unusual character in file names, so there's not much risk of colliding the file name chosen by the user. Why a tilde? Tildes are especially unusual at the beginning of file names, because a leading ~ means “home directory” in shells and many other programs. So prepending a tilde is unlikely to cause a collision. A possible additional factor because when it's at the end of a file name, it's a traditional way to name backups, so adding a tilde to a file's name has a flavor of “some file that is related to this other file, but is not the one the user usually wants” (but it couldn't be at the end because that's already taken). The tilde may additionally have been inspired by the lock files used by Microsoft Office, which start with ~$.

The hash at the end ensures that the file doesn't have an extension that other programs would recognize. If the file was called .~lock.MyDocument.odt, file managers would offer to open it in LibreOffice. Why a hash rather than some other character? Hash has a small tradition of being used in lock file names, for example Emacs uses .# followed by the name of the file that's being edited.

2

If a program uses a lock file for anything, it is up to the program to choose the name of that lock file.

The name chosen by LibreOffice seems to be a hidden name constructed in such a way that it's unlikely to collide with a pre-existing filename, while still being specific to whatever document you are currently editing.

  • So while the "." obviously hides the file the "~" and the "#" are arbitrary? – Silicomancer Apr 27 at 9:46
  • 1
    @Silicomancer Yes, they are prepended and appended to the name of your file and it creates a filename that is unlikely to exist. – Kusalananda Apr 27 at 9:48
  • 1
    @Silicomancer They are arbitrary, but not random, meaning LibreOffice will always name lock files in this way (as will OpenOffice I believe). – Kusalananda Apr 27 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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