Rescue Operation
Recovering LibreOffice Files
LibreOffice is a stable office suite, but accidents can happen.
LibreOffice is deservedly known for its stability. However, crashes and file corruptions do occasionally happen, most often when a system runs out of memory. Fortunately, there are several ways to recover a file, and if one fails, the chances are that another one will. Below are the recovery options, listed in order of how easy they are to use:
The easiest solution is to be proactive and prepare for recovery before it is needed. Before doing any work in LibreOffice, go to Tools | Options | LibreOffice | General | Save. There, select Save autorecovery information. The default to save every 10 minutes is usually good enough for most purposes, but you can change that as needed, or you can select Save the document instead. Note, however, that if you save too often, you suffer constant interruptions if you have limited memory. You should also select Always create backup. The backup location is defined in Tools | Options | LibreOffice | Path, and by default is /home/USER/.config/LibreOffice/4/user/backup. Alternatively, you can select Place backup in same folder as document. Probably the safest place for the backup is on another filesystem, or, best of all, an external drive. All of these options are turned off by default, presumably to save memory, but they can minimize the loss of data. By using worst, you will only lose a few minutes of work (Figure 1).
However, when working in LibreOffice, the first step in recovery should be to reopen the file. Upon restarting, LibreOffice will have the option to open any file that was not properly quit when the last session ended, regardless of whether it crashed or was simply overlooked when you exited. Given that the icon for closing a file is directly below the icon to close the whole of LibreOfffice, closing a file improperly can be all too easy.
File Surgery
If LibreOffice’s built-in recovery tools fail, you can try to dissect and perform surgery on the file itself. Although LibreOffice’s Open Document Format (ODF) is usually treated as an independent format, structurally it is simply a collection of zipped .xml files. That means that it can be opened in a file compression tool such as plasma’s Arch (Figure 2) or Gnome’s File Roller. For example, in a Writer file, if you only want the raw text, you can decompress content.xml (Figure 3) and run this bash command:
grep -C NUMBER ‘<text:span*’ content.xml
In this command, the -C option prints out lines that starts with the string ‘<text:span*>*’. The number is the number of instances that will be printed to output and may have to be adjusted several times before you get the entire contents. Once you have collected the entire text, copy it to a file, then search for ‘<text:span*’ and replace it and the corresponding end tag with nothing. You will be left complete, unformatted text, which is hardly ideal; although, most of the essential elements except for formatting and graphics are recovered. But of course if you have linked to graphics rather than embedded them in the file, you will still have them.
You can also transplant content.xml to another file, or else replace setting.xml and style.xml in the original document. However, this tactic will be hit and miss unless the original document is based on a template. Whether the effort is worth your time depends on how important the document is to you.
The Headache of File Deletion
But what if a file is deleted? In a desktop environment, the deleted file may still be in the Trash. However, if not, then your chances of success can be much lower. Extundelete may help if the deleted file is on an ext4 partition, and a better choice might be PhotoRec, which searches for file characteristics rather focusing on a particular filesystem. However, unless you attempt recovery immediately, your subsequent work might over-write a deleted file, especially on a filesystem whose memory is almost full.
Which brings me back to the beginning: The quickest and easiest way to recover files is be prepared. In addition to setting the options for autorecovery and backups in LibreOffice, always have a live disc available. Your chance of recovering a deleted file is improved with a live disc because you are less likely to overwrite the partition the deleted disk is on.
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Digital Autonomy
• The Answer Was Already on the Shelf
• Changing the Chip Industry: How Public Investment Has Grown Open Silicon
• United Nations Open Source Portal Goes Live
• EU Open Source Strategy Plays Key Role in Tech Sovereignty Package
• France Says “Au Revoir” to Microsoft
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Linux Mint Shares a Possible Kernel Cleanup Solution
For those on Linux Mint who like to keep multiple kernels around but don't want them to take up too much space, you might be getting a new automated tool.
-
CachyOS Gets an Update
CachyOS August 2026 release is now available with the latest version of KDE, some new features, and plenty of improvements.
-
The Linux Kernel Dev Staging Area Now Rejects AI-Generated Patches
Unless a kernel patch is a valid security fix, it will be rejected if it was created using AI.
-
Linux Surpasses Double-Digit Market Share
According to two sources, the Linux operating system has hit a major milestone in market share that naysayers thought would never happen.
-
AI Helped Develop a Linux Exploit
A use-after-free race exploit was discovered and exploited on CentOS Stream 9.
-
Yet Another Linux Kernel Vulnerability Discovered
Affecting millions of systems, a kernel flaw discovered by Qualys could allow users to gain root privileges.
-
Ubuntu 26.10 to Include Ubuntu Certified Hardware Check
If you've ever wondered if your laptop or PC is officially certified to run Ubuntu, that curiosity will soon be met.
-
Substantial Update to IPFire Now Available
The lastest version of IPFire features a fundamental change to how the system handles DNS.
-
Gnome Working on Test Center App to Make Testing Easier
It's now possible to test experimental features on the Gnome desktop without worrying that you'll break things.
-
New Vulnerability Discovered in Linux Kernel
Hiding out for nearly 15 years, the Ghostlock vulnerability allows a standard logged-in user to gain root privileges.
