Recovering deleted versions and files in Linux: an advanced guide

Last update: 22/02/2026
Author Isaac
  • Recovering all historical versions of a file in Linux without previous backups is virtually impossible: the system does not save those states.
  • The best options involve snapshots (LVM, Btrfs, ZFS) and backups that are well planned from the beginning.
  • Tools like Foremost, PhotoRec, R-Linux or Rescuezilla allow you to recover deleted files if they have not been overwritten.
  • Acting quickly, not writing to the affected disk, and choosing the right tool for your skill level will determine your chances of success.

Recovering file versions in Linux

If you've been working with Linux for a while, sooner or later you'll run into the situation where you've accidentally modified or deleted an important file . A misspelled command, a redirect with a simple ">" where it should be ">>", a botched update... and suddenly that critical document, those photos, or the system configuration is no longer where it should be.

The first thing to understand is that in Linux there's no magic bullet for recovering all historical versions of a file unless you've set up a backup or snapshot system yourself (for example, with LVM, Btrfs, ZFS, etc.). Even so, there are many forensic techniques and tools that offer a chance, sometimes minimal, of recovering deleted or overwritten data. The key is understanding what's possible, what isn't, and how to act quickly to avoid making the situation worse.

Why is it almost impossible to recover all versions of a file in Linux?

When we talk about recovering "all versions" of a modified file on a classic Linux/Unix system (with ext2/3/4, ReiserFS, etc.), we're entering the realm of science fiction if there are no previous backups. The reason lies in how the file system manages inodes and file content.

In systems like ext2, ext3, or ext4, a file is identified by its inode plus the filename . The inode contains metadata (permissions, dates, size, pointers to data blocks, etc.). When you edit a file, for example, from "a" to "A_modified", the inode number usually remains the same: its data is simply updated. A new inode is not created for each version.

This means there are no "old versions" of the same file floating around the disk with a different inode that you could hunt down. In practice, you could only recover fragments or previous states if, due to how the blocks were overwritten, there are remnants that a forensic tool can identify and reconstruct.

It is often said that there are one or two file systems (not very common on the desktop) where the inode number can change when rewriting the file, but this is certainly not the case with ext2/3/4 or ReiserFS , which are common in most classic distributions.

Therefore, when someone asks if it's possible to recover all versions of a file that has been modified over time without backups, the realistic answer is that the odds are dangerously close to 0,0…1% . Without snapshots or previous backups, the only option left is very limited forensic analysis.

Snapshots, LVM and partitioning best practices

It's one thing to be unable to perform miracles after the fact, and quite another to fail to prepare the system to minimize disasters . This is where sensible partitioning and technologies like LVM with snapshots come into play.

Modern installations of many distributions (CentOS, openSUSE, Ubuntu, etc.) often suggest two almost magical options during partitioning: use /home on a separate partition and use an LVM-managed file system . If you accept these suggestions, you're already one step ahead in terms of recovery.

Having a separate /home directory allows you to reinstall or update the system without affecting your personal data. And LVM adds a very powerful extra feature: volume snapshots . Snapshots are photographs of the file system's state at a given moment, from which you can revert or at least mount that snapshot and copy any data you may have corrupted.

Many people consider LVM something "server-level" or too advanced for a home laptop, but it's actually one of the best decisions to avoid problems , along with separating the root directory from /home. That said, on very basic machines or laptops where you're looking for the bare minimum, you can live without LVM, but you lose the ability to take instant snapshots.

In short: if you really want to have "versions" of your files, the serious way is to use snapshots (LVM, Btrfs, ZFS) or an automated backup system , not relying on recovering something that the system has never saved as a previous version.

How file deletion works in Linux and what recovery options are available

There's a common misconception that deleting a file makes it disappear from the disk immediately. In reality, in most file systems, the physical content remains until other data reuses that space.

When you delete a file, the system marks its blocks as free in its internal structures (inode tables, MFT in NTFS, etc.). The file no longer appears in directory listings, but the data may remain intact for a while. The less write activity there is on the drive after deletion, the better your chances of recovering something.

In Linux, the specific behavior depends on the file system: Ext2/3/4, XFS, JFS, ReiserFS, UFS, Btrfs, as well as FAT32/exFAT on removable devices. Some systems perform better than others in terms of recovery: for example, XFS and Btrfs usually offer reasonably good results, while in Ext2/3/4, fragmentation and the way blocks are managed make things considerably more complicated.

There's one particularly tricky case: SSDs with TRIM enabled . If you delete a file on an SSD and TRIM comes into play, the drive's firmware can physically erase those blocks almost immediately. In that situation, recovery is usually impossible , or extremely limited.

  How to create a Live USB with Tails OS: a complete and straightforward guide

Another point to consider is how the file is deleted: if you do it through the graphical interface, it usually goes to the Trash first, giving you a quick way out. But if you do it with `rm` from the terminal , there's no easy way back; there's no integrated Trash in that process.

Typical errors that cause data loss in Linux

Beyond the typical "I emptied the trash without looking," in Linux there are two major classics of massive data loss : careless abuse of the command line and accidental overwriting.

In the terminal, a single incorrectly copied line can be disastrous. There are "tricks" circulating online that promise to clean the system but actually execute `rm -rf` on critical paths . When you're new to Linux, it's wise to be wary of any command you don't fully understand, especially if it includes wildcards, unusual pipes, or absolute paths.

Another common pitfall is redirecting the output of a command with the wrong operator: ">" overwrites, ">>" appends . Using ">" on an existing file can empty it in no time, losing configurations, scripts, or documents in a second due to a simple typing error.

Added to this are hardware failures (dying hard drives, corrupted USB drives, bad sectors), partitioning errors with tools like fdisk or gparted, poorly planned reinstalls, and even failed system updates . Many users comment that in some distributions, upgrades between major versions are a gamble: on personal machines, jumping from one LTS to another or from 12.04 to 12.10, for example, can break things; in contrast, more conservative distributions like CentOS tend to offer more stable version upgrades.

That's why it's vital not only to have backups, but also to install the system properly : a separate /home directory, preferably with LVM, and always with a backup plan to revert to a previous version in case of a problematic update.

Forensic recovery with Foremost: file carving from the terminal

One of the classic tools for recovering deleted files in Linux is Foremost , a forensic analysis program based on file carving. It was originally designed for military use (AFOSI) and later released as public software.

The idea behind this is simple to understand: when metadata (inodes, table entries, etc.) is lost, you can still try to locate files by their characteristic internal structure . Many file types begin (and sometimes end) with a very specific hexadecimal header or pattern. For example, many GIFs begin with the bytes 47 49 46 38 39 61, which correspond to "GIF89a".

Foremost scans the drive looking for these patterns and, when it finds one, assumes that a file of that type begins there . From that point, it attempts to read until it detects the corresponding end marker or reaches the maximum size defined for that format. Then it dumps that content into an output directory, without restoring the original name or path, but at least recovering the data.

By default, Foremost can work with a wide range of formats: images (jpg, gif, png, bmp, tiff), video (avi, mp4, mov, mpg, wmv, asf), audio (wav, wma, mp3, riff), documents (doc, docx, xls, xlsx, ppt, pptx, pdf, txt, html), executables (exe), compressed files (zip, rar, rpm), and many more . It can also be configured to focus on only certain types using the -t option.

The interesting thing is that the /etc/foremost.conf configuration file allows you to add signatures for new file types , such as LibreOffice or OpenOffice documents (.odt, .ods, .odp, etc.) or Thunderbird data (.msf), specifying header patterns and an approximate maximum size.

Foremost Installation and Basic Use

Foremost is usually present in the repositories of almost all distributions, so installation is reduced to a command like sudo apt install foremost (in Debian, Ubuntu and derivatives) or the equivalent in your distro.

Its basic operation can be summarized as follows:

  • Choose an output directory where the recovered files will be stored.
  • Identify the drive or partition that you want to scan (for example, /dev/sdb1 for a USB drive).
  • Run Foremost specifying file types (-t), input device (-i) and output directory (-o).

Suppose you've deleted photos and PDFs from a USB drive and want to recover everything. You could first create a working folder, for example on your Desktop:

mkdir /home/usuario/Escritorio/Recuperacion

Then, you detect the device name with:

sudo fdisk-l

and you see that your USB is /dev/sdb1. Then you can launch:

sudo foremost -t all -i /dev/sdb1 -o /home/usuario/Escritorio/Recuperacion

Foremost will scan the entire device, sort the results by extension into subfolders within Recovery, and when finished, you'll have a good number of renamed but potentially useful files: .jpg in its folder, .pdf in its own, .doc, .xls, .ppt, etc.

Important tips when using Foremost

To maximize the chances of success, there are a number of key recommendations when using Foremost or similar tools:

  • Do not write anything to the same partition from the drive you want to recover data. Always save the recovered files to a different drive, such as an external hard drive or a USB drive.
  • Act as soon as possible After deleting the file, every minute that passes and every write operation the system performs increases the probability that the blocks you're interested in will be overwritten.
  • If the file is extremely important, Turn off the machine and work from another systemby connecting the disk as a secondary disk or booting with a LiveCD/LiveUSB, even creating an image with dd and working on that image so as not to touch the original disk.
  • Foremost can operate on images created with dd, Safeback, EnCase, and othersCreating an image and working with it is the most prudent way to conduct forensic analysis.
  What is lsass.exe: Features, Risks, and Solutions in Windows

Once Foremost has finished, the output directory will be owned by root (because you ran it with sudo). To be able to open it without problems from your user , it's best to change the owner recursively, for example:

sudo chown -R user /home/user/Desktop/Recovery

Inside, you'll see folders organized by file extension. If, for example, you were looking for a PowerPoint presentation, you'd enter the ppt folder and be able to open files until you find it. Foremost often recovers more than you expect , including files you deleted a long time ago or that were on the device before you used it.

Alternatives to Foremost and other recovery tools in Linux

Although Foremost is very popular for being powerful and easy to use, the Linux ecosystem offers many more tools to try to recover data , both in text mode and with graphical interfaces or even complete distributions oriented to rescue.

Among the classic command-line alternatives are Scalpel, PhotoRec, Autopsy, extundelete, and magicrescue , which employ similar principles (file carving, file system structure analysis, etc.). Some require modifying configuration files to define which file types to search for, which is more cumbersome than simply using Foremost's `-t` command.

Furthermore, more comprehensive solutions exist, ranging from graphical interfaces for low-level tools to complete Live systems loaded with rescue utilities. Some are free, others are paid, but they all share the basic idea: avoid writing to the damaged disk and thoroughly scan for any usable traces.

GNU DDRescue-GUI: graphical interface for GNU DDRescue

GNU DDRescue is a powerful tool designed to copy data from damaged devices (hard drives with bad sectors, scratched CDs, etc.) to another drive, always prioritizing the copying of still readable areas and leaving the problematic sectors for later.

Unlike a "plain" dd, DDRescue does not write zeros by default in the gaps where it finds errors or truncate the output file: it leaves gaps and fills them little by little in successive passes, which allows you to get the most out of several defective copies of the same medium and merge the valid information from all of them into a single final image.

The problem for many users is that DDRescue is managed from the terminal. To make it more user-friendly, there's GNU DDRescue-GUI , a graphical interface that simplifies selecting the source, destination, copy parameters, and so on. Functionally, it does the same thing as the original tool, but without forcing you to remember all the syntax.

The interface isn't exactly a marvel of modern design, but it's much more convenient than dealing with long commands when you're under pressure trying to save data from a dying disk.

Redo Rescue: Easy backup and restore

Redo Rescue is an ISO format solution that you boot from a CD or USB and that allows you to both clone and restore entire systems as well as recover data from partitions.

It's designed for inexperienced users: its interface is very simple and it comes with integrated tools (text editor, browser, file manager, terminal). Internally, it uses Partclone to clone partitions , making it easy to create complete system backups before making any significant changes.

For those who just want "something that works" without messing around with commands, Redo Rescue is a very interesting option: you start it up, choose what you want to clone or restore , and that's it. What it doesn't offer is very fine-grained control over partitioning details, something that advanced users will miss.

TestDisk and PhotoRec: a classic command-line pair

TestDisk is a well-known open-source tool for recovering lost partitions, repairing damaged partition tables, rebuilding the MBR, fixing boot problems, and more. It's a text-based interface, but its graphical interface is quite intuitive, so even non-expert users can navigate the menus with relative ease.

PhotoRec, which is often bundled with TestDisk, focuses on recovering individual files (primarily photos and multimedia, but also many other types). It ignores the file system and simply searches for header and footer patterns in the raw disk data, so it can work even when the file system is completely corrupted or the disk has been formatted.

The biggest drawback of PhotoRec is its lack of a native graphical interface; everything is done via the terminal. In return, it offers a level of detail that often compensates for the effort, especially for advanced users who need to scrape every last byte of data from SD cards, USB drives, or damaged hard drives.

SystemRescueCD and Knoppix: Live distributions for rescue

When the problem is not just a deleted file, but the system doesn't even boot or the partition is seriously damaged, the most practical thing to do is usually to use a rescue-oriented Live distribution.

SystemRescueCD is precisely that: a bootable medium (CD/USB) with a very comprehensive set of tools for repairing Linux systems , managing partitions (with GParted and low-level utilities), checking and repairing file systems, and working with backups thanks to FSArchiver, among others.

It supports most common file systems (Ext4, XFS, Btrfs, VFAT, NTFS, and even network file systems like Samba or NFS). It's a very complete toolbox, but it's geared towards users with some experience: it's not a "next, next, finish" kind of environment, but rather one for administrators who already know what they're doing.

Knoppix, on the other hand, is a general-purpose Live distribution, but it includes a large number of data recovery utilities . Its main purpose is not to be your daily desktop system, but to give you a bootable environment from USB or CD with which to access damaged disks or systems that won't boot, and from there use the included tools to try to recover files.

  Tutorial: How to Delete Unwanted Files or Folders in Windows

The main requirement for getting the most out of Knoppix is ​​a certain level of familiarity with Linux: the tools are there, many are free and powerful, but they're not "magic clicks ." You need to know what you're doing to avoid making the problem worse.

R-Linux, Mondo Rescue and Rescuezilla: solutions with a graphical interface

R-Linux is a free data recovery tool for Ext2/Ext3/Ext4 file systems . It allows you to recover files deleted due to system crashes, power outages, malware attacks, accidental formatting, and even partition structure changes, as long as the data has not been overwritten.

It stands out because it offers a fairly comprehensive graphical interface and allows you to save recovered files to virtually any disk accessible from the system, including network drives. It can also search for different "versions" of the same deleted file based on its size, name, extension, or recognized type, which helps refine the search.

The major limitation is that it cannot recover data over the network or rebuild RAID arrays . For that, its more expensive sibling, R-Studio, comes into play, but R-Linux covers home and small office scenarios very well.

Mondo Rescue, on the other hand, is a Linux and FreeBSD solution focused on full system backups and recovery . It supports RAID, LVM, XFS, VFAT, JFS, Ext2/3, and allows you to create backups on CD, DVD, or USB, reorganize partitions before restoring, and modify key files such as /etc/lilo.conf or /etc/fstab during the process.

Its interface may look a bit dated, but it's relatively easy to use even if you're not a Linux expert. It's a good option for planning complete system restores after major disasters (changed disks, corrupted partitions, etc.).

Finally, RescueZilla is an open-source tool geared towards the average user. It runs from a bootable USB drive and allows you to clone hard drives using images, recover partitions, and access the data from those images to extract only what you need.

Its interface is quite user-friendly and doesn't require advanced knowledge, making it ideal for those who simply want to recover files without struggling with command lines . However, it consumes more resources than one might expect on some modest computers and, currently, doesn't support ARM architectures like Apple Silicon.

Commercial Software: UFS Explorer Standard Recovery

In addition to all the free solutions, there is commercial software specifically designed for Linux environments and file systems typical of this ecosystem . One example is UFS Explorer Standard Recovery, which can work with Ext2/3/4, XFS, JFS, ReiserFS, UFS, Btrfs, FAT32/exFAT, etc., and with simple volumes, LVM, mdadm, and distributed sets.

The philosophy is the same: unmount the partition or, better yet, connect the disk to another machine in read-only mode , scan it with the program, preview the files found, and save them to a different storage device. For systems where the disk cannot be removed (for example, if the data is in /root and you cannot unmount it), they even offer an emergency CD that boots the computer and allows you to perform the recovery from outside the installed system.

These paid solutions often stand out for offering polished interfaces, wizards, and advanced filtering features , but essentially they do the same thing as many free tools combined: scan, list, and copy what has not yet been overwritten.

Which tool to choose based on your level and your problem

When deciding which tool to use to tackle a data disaster in Linux, it's important to consider two things: your actual experience with the system and the type of problem you're dealing with.

If you're a beginner or not comfortable with the terminal, the wisest option is to choose solutions with a graphical interface and, if necessary, bootable from USB: Redo Rescue, GNU DDRescue-GUI, Rescuezilla, or R-Linux are all excellent choices. They'll guide you through the process and reduce the likelihood of making things worse.

If you already have some experience, command-line tools like TestDisk, PhotoRec, Foremost, or Scalpel will give you more control and potentially better results in complex cases, in exchange for requiring more care and patience.

When disaster affects the entire system (it won't boot, partitions are missing, etc.), a specialized Live distribution like SystemRescueCD or Knoppix gives you a complete environment to work from without touching the damaged disk when booting.

And if you're in a professional environment or the data has clear economic value, it might make sense to consider commercial solutions like UFS Explorer Standard Recovery or simply go to a professional recovery service to avoid worsening the state of the device.

In any case, however much these tools can help you save the day, the truly important thing is to accept that recovering all versions of a modified file in Linux without backups is virtually impossible . What you can do is design a sensible strategy now: separate partitions, LVM or snapshot systems, regular backups, and a healthy respect for the command line. With that foundation, if something goes wrong, your chances of success will be infinitely better than relying on last-minute forensic miracles.

Recover deleted files with TestDisk & PhotoRec-3
Related articles:
How to recover deleted files with TestDisk and PhotoRec