Steps to Restore a Deleted Folder in Ubuntu
If you have accidentally deleted the /home/user/Downloads/test folder on Ubuntu, the recovery method depends on how it was deleted and whether you have backups. Below are the main approaches:
Check the Trash (Recycle Bin) First
- If you deleted the folder using the file manager (GUI) and did not use Shift+Delete or the
rm command, your folder may be in the Trash.
- Open the Files app.
- Navigate to Trash in the sidebar.
- If you see the
test folder, right-click and select Restore. This will return it to its original location[7][5].
If the Folder Was Deleted Using Shift+Delete or rm (Permanently Deleted)
Once a file or folder is permanently deleted (bypassing Trash), recovery is more complex. The sooner you attempt recovery, the better your chances, as new data can overwrite the deleted files.
1. Stop Using the Affected Partition
- Avoid writing new data to
/home/user/Downloads or the partition, as this can overwrite recoverable files[1][9].
2. Use TestDisk (Recommended for Most Users)
TestDisk is a powerful, free tool for recovering deleted files on Linux.
Install TestDisk
sudo apt update
sudo apt install testdisk
Create a Recovery Directory
mkdir ~/recovery
cd ~/recovery
Run TestDisk
sudo testdisk
- Choose to create a new log file.
- Select the disk where your
/home directory resides (often /dev/sda1).
- Choose the partition type (usually detected automatically).
- Select Advanced > choose the partition > Undelete.
- Navigate to
/home/user/Downloads/ and look for the test folder or its contents.
- Select the files/folders you want to recover and press
c to copy.
- Choose your
~/recovery directory as the destination and press C (uppercase) to confirm[6][8][9].
Change Ownership (if needed)
Recovered files may be owned by root. Change ownership with:
sudo chown -R $USER:$USER ~/recovery
3. Alternative Tools
- PhotoRec: Also included with TestDisk, recovers files by type but may not preserve original filenames or directory structure[3][9].
- extundelete: Works on ext3/ext4 filesystems, but requires the partition to be unmounted for best results. Use only if you can safely unmount
/home or work from a live USB[1][9].
- Scalpel: Another file carving tool, but less user-friendly[4].
4. Check Backups
If you have backups (using Ubuntu’s Deja Dup or other tools), restore the folder from your backup[7].
Summary Table
| Method | Preserves Structure | Requires Unmount | Ease of Use | Notes |
|---|
| Trash/Recycle | Yes | No | Easy | Only if not permanently deleted[7][5] |
| TestDisk | Yes | No | Moderate | Works on mounted partitions[6][8][9] |
| PhotoRec | No | No | Moderate | Recovers by file type only[3][9] |
| extundelete | Yes | Yes (recommended) | Advanced | For ext3/ext4 only[1][9] |
| Backup Restore | Yes | No | Easy | If backup exists[7] |
Key Tips
- Act quickly: The more you use your system, the lower your chances of recovery.
- Do not install recovery tools on the affected partition: Use a different partition or a live USB if possible.
- Always back up important data regularly.
If you need step-by-step guidance for a specific tool (e.g., TestDisk or extundelete), let me know which method you prefer.