๐Ÿง TestDisk Command Guide for Linux (Recover Lost Partitions & Data)

๐Ÿง TestDisk Command Guide for Linux (Recover Lost Partitions & Data)
Operating System(s)

TestDisk is a powerful open-source tool used to recover lost partitions, repair partition tables, and restore boot sectors on Linux systems.

๐Ÿ“ฆ Install TestDisk

Ubuntu / Debian

 

sudo apt update
sudo apt install testdisk

 

Fedora

 

sudo dnf install testdisk

 

Arch Linux

 

sudo pacman -S testdisk

 

โ–ถ๏ธ Launch TestDisk

Run with root privileges:

 

sudo testdisk

 

๐Ÿงญ Basic Navigation Controls

  • Arrow keys โ†’ Move
  • Enter โ†’ Select
  • Q โ†’ Quit / Go back

๐Ÿ”ง Step-by-Step: Recover Lost Partitions

1. Create a Log File

  • Select Create โ†’ Press Enter

2. Select Your Drive

  • Choose your disk (e.g., /dev/sda)
  • Press Enter

3. Select Partition Table Type

  • Usually auto-detected:
    • Intel/PC (MBR)
    • EFI GPT (modern systems)

4. Analyze the Disk

  • Select Analyze
  • Press Enter
  • Choose Quick Search

5. View Found Partitions

  • Highlight a partition
  • Press P to preview files

โœ” If files look correct โ†’ proceed

6. Write the Partition Table

  • Press Enter โ†’ Select Write
  • Confirm with Y

โš ๏ธ Reboot after writing changes:

 

sudo reboot

 

๐Ÿ› ๏ธ Recover Deleted Files (Advanced)

TestDisk includes PhotoRec for file recovery:

 

sudo photorec

 

  • Select drive
  • Choose file types
  • Pick recovery location

โœ” Recovers files even from damaged partitions

โš ๏ธ Important Tips

  • Always run as root (sudo)
  • Avoid writing to the affected drive before recovery
  • Use a separate drive for recovered files
  • GPT systems are common on newer PCs

๐Ÿง  When to Use TestDisk

  • Lost or deleted partitions
  • Corrupted partition tables
  • System wonโ€™t boot
  • Missing drives after OS install

๐Ÿ” Alternative Tools

  • GParted (GUI partition tool)
  • ddrescue (advanced disk recovery)
Force Cache (Faster Mirror)

Linux Commands

Files

tar ยท pv ยท cat ยท tac ยท chmod ยท grep ยท  diff ยท sed ยท ar ยท man ยท pushd ยท popd ยท fsck ยท testdisk ยท seq ยท fd ยท pandoc ยท cd ยท $PATH ยท awk ยท join ยท jq ยท fold ยท uniq ยท journalctl ยท tail ยท stat ยท ls ยท fstab ยท echo ยท less ยท chgrp ยท chown ยท rev ยท look ยท strings ยท type ยท rename ยท zip ยท unzip ยท mount ยท umount ยท install ยท fdisk ยท mkfs ยท rm ยท rmdir ยท rsync ยท df ยท gpg ยท vi ยท nano ยท mkdir ยท du ยท ln ยท patch ยท convert ยท rclone ยท shred ยท srm ยท scp ยท gzip ยท chattr ยท cut ยท find ยท umask ยท wc ยท tr ยท hash  ยท compgen

Processes

alias ยท screen ยท top ยท nice ยท renice ยท progress ยท strace ยท systemd ยท tmux ยท chsh ยท history ยท at ยท batch ยท free ยท which ยท dmesg ยท chfn ยท usermod ยท ps ยท chroot ยท xargs ยท tty ยท pinky ยท lsof ยท vmstat ยท timeout ยท wall ยท yes ยท kill ยท sleep ยท sudo ยท su ยท time ยท groupadd ยท usermod ยท groups ยท lshw ยท shutdown ยท reboot ยท halt ยท poweroff ยท passwd ยท lscpu ยท crontab ยท date ยท bg ยท fg ยท pidof ยท nohup ยท pmap

Networking

netstat ยท ping ยท traceroute ยท ip ยท ss ยท whois ยท fail2ban ยท bmon ยท dig ยท finger ยท nmap ยท ftp ยท curl ยท wget ยท who ยท whoami ยทยท iptables ยท ssh-keygen ยท ufw ยท arping ยท firewalld