How to Recover Permanently Deleted Files on Mac Using Terminal

Losing files on a Mac is stressful – and Terminal is often the first thing people reach for. It can help, but only in specific situations. Here’s the honest answer upfront: Terminal can restore deleted files only if they’re still sitting in the .Trash folder. Once you empty the Trash, or delete a file with the rm command that bypasses Trash entirely, standard Terminal commands cannot get those files back – and that’s where data recovery software like Disk Drill becomes necessary. So before you spend an hour typing commands that won’t work – this guide covers what Terminal actually does, where it hits a wall, and what to do from there.
Stop using your Mac immediately if you realize files are missing. Every new file written to the drive can overwrite the data you’re trying to recover – especially on SSDs with TRIM enabled.
What Can Mac Terminal Do for File Recovery?
Mac Terminal is a powerful command-line interface, but its data recovery abilities are limited to what’s still in the file system index. Understanding exactly where it helps – and where it stops – saves time and prevents accidentally overwriting data you’re trying to rescue.
| Situation | Terminal can help? |
|---|---|
| File moved to Trash, Trash not emptied | ✅ Yes |
| File deleted from external drive, Trash not emptied | ✅ Yes |
| Time Machine backup exists | ✅ Yes |
| Trash emptied after deletion | ❌ No |
File deleted with rm command | ❌ No |
| Files lost after macOS update or crash | ❌ No |
| Drive formatted or corrupted | ❌ No |
Why can’t Terminal recover permanently deleted files? When you empty the Trash, macOS removes the file’s directory entry. Terminal navigates the file system index – once that entry is gone, Terminal has nothing to work with. Data recovery software reads raw sectors directly, bypassing the index entirely, which is why it finds files Terminal cannot.
Step-by-Step Guide. Recover Permanently Deleted Files Mac Terminal:
Method 1: Recover from Trash Using Terminal Commands 💻
If you’ve deleted files recently and haven’t yet emptied the Trash, Terminal gives you a command-line path to restore them. This is useful when Finder isn’t accessible, when you’re dealing with hidden files, or when you simply prefer working in the command line.
Before starting, give Terminal Full Disk Access: open System Settings – Privacy & Security – Full Disk Access and toggle Terminal on. Without this on modern macOS, Terminal may not see everything in the Trash.
- Open Terminal from Applications – Utilities, or search with Command + Space.
- Navigate to the Trash folder:
cd ~/.Trash
- List the contents to see what’s there:
ls -la
- Move the file back to your Desktop (replace
report.pdfwith your actual filename and extension):
mv report.pdf ~/Desktop/
- If the filename contains spaces, wrap it in quotes:
mv "my report.pdf" ~/Desktop/ - To restore to a different location, replace
~/Desktop/with your desired path, such as~/Documents/. - Open Finder and verify the file is back in the target location.
Note: File names in Terminal are case-sensitive. If report.pdf returns an error, try Report.pdf. Also, ~/.Trash only covers your user’s Trash – files deleted from external drives go to a separate location (see Method 3).
Best for: Files moved to Trash that haven’t been permanently deleted yet.
Method 2: Restore from Time Machine via tmutil ⏱️
If you have Time Machine set up, the tmutil command in Terminal gives you scriptable access to your backups – useful when you know exactly which file you need and want to skip the Time Machine GUI.
- Connect your Time Machine backup drive.
- Open Terminal and list available backups:
tmutil listbackups
- Identify the backup by date (backups are stored as
/Volumes/TimeMachineBackup/Backups.backupdb/MacName/YYYY-MM-DD-HHMMSS/). - Restore the specific file with
tmutil restore, specifying the source path and destination:
tmutil restore /Volumes/TimeMachineBackup/Backups.backupdb/MacName/2026-05-01-120000/Macintosh\ HD/Users/yourname/Documents/report.pdf ~/Desktop/
- Confirm the file appears at the destination path.
Note: tmutil requires Time Machine to have been active before the file was deleted. If no backup exists, move to Method 4.
Best for: Restoring specific files from an existing Time Machine backup via command line.
Method 3: Check the .Trashes Folder on External Drives 💾
When you delete a file from an external drive, macOS doesn’t send it to ~/.Trash. Instead it goes to a hidden .Trashes folder on that external volume. Terminal can access this directly before the Trash is emptied.
- Connect the external drive where the file was deleted.
- Navigate to its Trashes folder (replace
DriveNamewith your drive’s name as shown in Finder):
cd /Volumes/DriveName/.Trashes
- List contents:
ls -la
- You’ll see a subfolder named after your user ID (a number like
501). Navigate into it:
cd 501
- Restore the file to your Desktop:
mv filename.ext ~/Desktop/
Note: This only works if the Trash for that volume hasn’t been emptied. If it has, use Disk Drill to scan the external drive directly.
Best for: Files deleted from USB drives, SD cards, or external hard drives before the Trash was emptied.
When Terminal Isn’t Enough: Recover Permanently Deleted Files with Disk Drill
When Terminal commands return nothing – because the Trash was emptied, the rm command was used, or files were lost in a crash or update – you need software that works at a deeper level than Terminal ever could. Disk Drill scans your drive sector by sector, reading raw data without relying on the file system index that Terminal depends on. It supports APFS and HFS+, works on both Intel and Apple Silicon Macs, and can recover documents, photos, videos, and archives even when they’re completely invisible to Finder and Terminal.
Important: Stop using your Mac immediately before running any recovery scan. Every write to the drive – including opening apps or saving files – risks permanently overwriting recoverable data, particularly on SSDs where TRIM erases deleted blocks in the background.
- Download and install Disk Drill from the official website. Install it on an external drive or a drive other than the one you’re recovering from – installing on the same drive can overwrite data you’re trying to find.
- Launch Disk Drill and grant it Full Disk Access when prompted – this allows it to scan system-protected areas where deleted files may be hiding.
- Select your Mac’s internal drive (typically labeled APPLE SSD or Macintosh HD) from the list of available disks.
- Click “Search for lost data.” Let the deep scan complete – it takes longer than a quick scan but finds significantly more recoverable data.
- When the scan finishes, click “Review found items.” Browse the Deleted or Lost tab and use the preview panel to verify files before selecting them. Disk Drill often reconstructs the original folder structure, so you can navigate to your original file path.
- Check the boxes next to the files you want to restore, click “Recover,” and save them to an external drive – never to the same disk being scanned.
Note: On Macs with APFS and SSD storage, TRIM progressively erases deleted data in the background. The sooner you run Disk Drill after deletion, the higher the recovery rate.
Free CLI Alternative: PhotoRec via Terminal
Using PhotoRec and TestDisk via Terminal 🔬
If you prefer staying entirely in the command line, PhotoRec (included in the TestDisk package) is a free open-source tool that can be installed via Homebrew and run directly from Terminal. It carves files by detecting their signatures in raw sectors – similar in principle to Disk Drill, but without the graphical interface and file preview.
Keep in mind its limitations before using it: PhotoRec does not preserve original file names or folder structure, so you’ll need to manually sort through recovered files. It also cannot access the system partition on Apple Silicon Macs (M1-M4) or T2-equipped Intel Macs due to hardware encryption – it works on external drives and secondary partitions only on those machines.
- Install Homebrew if not already installed:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Install TestDisk (which includes PhotoRec):
brew install testdisk
- Launch PhotoRec:
sudo photorec
- Use the arrow keys to select your disk, then select your partition (choose No partition to scan the whole drive).
- Select the file system type – PhotoRec will suggest the correct option automatically.
- Choose a destination folder on an external drive to save recovered files and press C to begin recovery.
- When complete, sort through the output folder to find your files – they will be renamed with generic identifiers.
Note: PhotoRec is powerful but produces a flat, unsorted list of recovered files with no original names. For most users, Disk Drill’s preview and folder structure reconstruction make recovery significantly faster and more practical.
Best for: Technically experienced users who want a free CLI tool and are comfortable manually sorting recovered files.
Precautions and Tips for Mac File Recovery:
Safeguarding Your Data 🛡️
- Stop using your Mac immediately after realizing files are missing. On SSDs, TRIM erases deleted data in the background – every minute counts on modern Apple Silicon and Intel Macs with NVMe storage.
- Avoid installing software, saving new files, or running macOS updates on the affected drive before completing recovery – each action can overwrite sectors that hold your lost data.
- Set up Time Machine with an external drive for ongoing protection. A backup from even a day ago can save hours of recovery effort. Learn how to use Time Machine.
- Consider a cloud backup such as iCloud Drive or Backblaze for your most critical files – cloud services often retain deleted file history for 30 days or more.
Enhancing Recovery Chances 🔍
- Always save recovered files to a different drive than the one being scanned. Writing to the source drive during recovery is the most common way to permanently destroy data you’re trying to rescue.
- If you use FileVault encryption, recovery is still possible with Disk Drill – but you’ll need your FileVault password or recovery key. Learn about FileVault.
- For a physically failing drive (clicking sounds, not mounting), don’t attempt software recovery. Contact a professional data recovery service – running scans on damaged hardware can cause further damage.
Final Thoughts:
Recovering permanently deleted files on Mac using Terminal is possible – but only in specific situations. If files are still in the Trash, the mv command restores them in seconds. If you have Time Machine, tmutil restore gets you to any backup quickly. But for files deleted after emptying Trash, removed with rm, or lost in a crash – Terminal cannot help. In those cases, Disk Drill is the most reliable path to recovery, or PhotoRec if you prefer a free CLI alternative. Whatever method you use, act quickly and stop writing to the affected drive until recovery is complete.
FAQ
How can I use Terminal on a Mac to attempt recovery of permanently deleted files?
Using Terminal, you can try the 'tmutil' command to restore from Time Machine backups or third-party file recovery tools with command-line interfaces.
Is it possible to recover files deleted from the Trash using Terminal commands?
Once files are emptied from the Trash, they cannot be restored using standard Terminal commands; specialized recovery software is necessary.
What command-line tools are available for file recovery on Mac?
Tools like PhotoRec and TestDisk can assist in recovering files and are accessible through Terminal. Explore further at CGSecurity.org.
Can I recover a permanently deleted file without any backups?
Recovery without backups may be possible using third-party data recovery software, which scans your disk for recoverable data.
Are there any native macOS utilities that can recover deleted files from the Terminal?
No native macOS utilities can recover deleted files from the Terminal once they're permanently removed; third-party software would be required.
Does Time Machine work with Terminal to recover files?
Yes, you can interact with Time Machine using the 'tmutil' command in Terminal to restore files from a backup.
What should I remember before attempting to recover files via Terminal?
Before attempting recovery, stop using the affected storage device to prevent overwriting deleted files and heighten the chances of recovery.
Do any file systems have better chances of recovery using Mac's Terminal?
File systems like HFS+ and APFS may offer different chances of recovery, but once data is overwritten, it's generally irrecoverable regardless of the file system.
Can I recover permanently deleted files from an SSD using Terminal on a Mac?
SSDs use a technology called TRIM, which makes recovery of permanently deleted files more difficult, often requiring professional services or advanced software.
Are there any reputable data recovery services you can suggest?
You may consider contacting professional services like DriveSavers for complex recovery tasks beyond the scope of DIY software.
ping.fm 