Scalpel Recover Deleted Files on Linux?
In this article
Yes, Scalpel can recover deleted files on Linux, but with an important caveat: it works by carving files from raw disk images or block devices based on file signatures, not by using the filesystem's metadata. This means it can often recover files even after the filesystem structure is damaged or the files have been "deleted," but it cannot recover files that have been overwritten or fragmented beyond recognition. In short, Scalpel is a powerful forensic tool for recovering specific file types, not a general-purpose undelete utility.
What Is Scalpel and How Does It Work?
Scalpel is an open-source file carving tool originally derived from Foremost, a similar utility developed by the U.S. Air Force Office of Special Investigations. It scans raw data—either a disk image file or a block device like /dev/sda1—looking for byte patterns that match the headers (and optionally footers) of known file types. When it finds a match, it extracts the data from that point onward, either until it finds the footer or until it reaches a maximum file size you specify.
This approach is fundamentally different from tools like extundelete or testdisk, which read the filesystem's journal and inode tables to locate deleted files. Scalpel ignores the filesystem entirely, which makes it useful when the filesystem is corrupted, formatted, or when you're dealing with a raw disk image from an unknown source. However, it also means Scalpel cannot know a file's original name, path, or creation date—it only recovers the content based on signatures.
When Should You Use Scalpel?
Scalpel is best suited for scenarios where the filesystem is not accessible or where you need to recover specific file types from a large amount of raw data. Common use cases include:
- Recovering photos, documents, or videos from a memory card after accidental deletion or formatting.
- Extracting files from a disk image created for forensic analysis.
- Recovering files after a partition table is lost or the filesystem is severely corrupted.
- Data recovery from a drive that has been partially overwritten but still contains intact file signatures.
If you simply deleted a file on a healthy ext4 filesystem and want it back quickly, tools like extundelete or testdisk are usually more effective because they can restore the file with its original metadata. Scalpel should be your choice when those tools fail or when you don't have a working filesystem to work with.
How to Install and Use Scalpel
Scalpel is available in the package repositories of most Linux distributions. On Debian/Ubuntu, install it with:
sudo apt install scalpel
On Fedora, use sudo dnf install scalpel, and on Arch, sudo pacman -S scalpel. Once installed, you need to configure Scalpel before running it. The configuration file is usually located at /etc/scalpel/scalpel.conf (or /etc/scalpel.conf on some distributions). This file lists all the file types Scalpel can carve, with each line specifying the file extension, a case-sensitive flag, the header signature in hex, and optionally the footer signature.
By default, all file types are commented out. You must edit the configuration file to uncomment the lines for the file types you want to recover. For example, to enable JPEG recovery, you would uncomment a line like:
jpg y 200000 \\xff\\xd8\\xff\\xe0 \\xff\\xd9
The fields are: extension, case-insensitive flag (y/n), maximum file size in bytes, header bytes in hex, and footer bytes in hex. After saving the configuration, you can run Scalpel on a disk image or block device:
sudo scalpel /dev/sdb1 -o /home/user/recovered
This command carves files from the partition /dev/sdb1 and writes the recovered files to the output directory. You can also use a raw image file, such as one created with dd or dcfldd.
Common Problems and Limitations
Scalpel is not a magic bullet, and several limitations can affect your recovery results:
- Fragmentation: If a file is fragmented across non-contiguous areas of the disk, Scalpel will only recover the first fragment (up to the footer or maximum size). This often results in corrupted files, especially for large files like videos.
- Overwriting: When you delete a file, the space it occupied is marked as free, but the data remains until overwritten. If the disk has been heavily used since deletion, the file's data may be partially or fully overwritten, making recovery impossible.
- False positives: Scalpel matches signatures, so random data that happens to contain the header bytes can be misidentified as a file, leading to garbage output.
- No metadata: Recovered files are named sequentially (e.g., 00000000.jpg, 00000001.jpg) and have no timestamps. You'll need to manually sort through the results.
- Performance: Scanning a large disk can take a long time, especially if you enable many file types. It's wise to limit the configuration to only the file types you actually need.
A common misconception is that Scalpel can recover files from a mounted filesystem. Running Scalpel on a mounted partition can cause further data loss because the system may write to the disk while it's being scanned. Always unmount the partition or use a read-only image.
How to Choose Between Scalpel and Other Tools
Choosing the right recovery tool depends on your situation:
- Scalpel – Use when the filesystem is damaged, formatted, or when you have a raw image. It's also great for carving specific file types from unallocated space.
- TestDisk – Best for recovering lost partitions or fixing boot sectors. It can also recover deleted files on some filesystems, but its main strength is partition recovery.
- PhotoRec – A companion tool to TestDisk that also does file carving, but with a more user-friendly interface and support for more file types. It's often a better choice for beginners because it doesn't require editing a configuration file.
- extundelete – Works on ext3/ext4 filesystems and uses the journal to recover deleted files with their original names and paths. It's faster and more accurate when the filesystem is intact.
In practice, many forensic analysts use both Scalpel and PhotoRec, as they complement each other. Scalpel is highly customizable, while PhotoRec is easier to run out of the box.
Safety and Best Practices for Data Recovery
Data recovery is a delicate process, and the most important rule is to stop using the drive immediately after you realize you've deleted important files. Any write operation—even mounting the filesystem—can overwrite the very data you're trying to recover. Follow these best practices:
- Unmount the partition: If the drive is mounted, unmount it before running any recovery tool.
- Work on a copy: Create a raw disk image with
ddand run Scalpel on the image, not the original drive. This preserves the original for further attempts. - Use a different drive for output: Never write recovered files to the same drive you're recovering from. Use an external drive or a different partition.
- Disable automounting: If you're recovering from an external drive, ensure your system doesn't automatically mount it when you plug it in.
Creating a disk image is simple: sudo dd if=/dev/sdb1 of=/mnt/external/image.dd bs=4M. Then run Scalpel on the image file. This adds a bit of time but is the safest approach.
Frequently Asked Questions
Can Scalpel recover files from an SSD?
Yes, but with caveats. SSDs use wear leveling and TRIM, which can permanently erase data blocks shortly after deletion. If TRIM is enabled (which it is by default on most modern systems), deleted files may be unrecoverable almost immediately. Scalpel can still work on SSDs if the data hasn't been trimmed, but the window of opportunity is much smaller than on a traditional hard drive.
Does Scalpel support NTFS or exFAT?
Scalpel doesn't care about the filesystem—it scans raw bytes. So yes, it can carve files from NTFS, exFAT, FAT32, or any other filesystem. However, it won't recover file names or directory structures, as those are filesystem-specific. For NTFS, you might get better results with tools like ntfsundelete or photorec.
Why are my recovered files corrupted?
Corruption usually happens because the file was fragmented on the disk. Scalpel stops carving at the footer signature, but if the file was split into multiple non-contiguous pieces, the footer will not be found at the expected location, and Scalpel will either stop at the maximum file size or at a false footer. This is a known limitation of all file carving tools.
Can I recover files from a formatted drive?
Yes, formatting typically only overwrites the filesystem structures, not the actual file data. As long as the data hasn't been overwritten by new files, Scalpel can still find and carve files from a formatted drive. This is one of its primary use cases.
Is Scalpel free to use?
Yes, Scalpel is open-source software released under the GPL license. It's free to download, use, and modify. It's included in most Linux distributions' repositories, and the source code is available on GitHub.