Many MacBook users try to avoid using the Terminal app because of its command-line interface. If you’re one of those people, then you’re missing out on a lot since this tool has awesome data recovery capabilities that can help bring your deleted files back. And don’t worry, there’s nothing complicated in using Terminal (our step-by-step instructions will guide you all the way).
How to Launch Terminal
Terminal is a native macOS application that comes preinstalled on all Macs. Therefore, this tool can be opened just like any other app that’s already installed on your computer.
Here’s how to locate and launch Terminal on your Mac:
- Open Finder (click the first icon from the left on the Dock).
- Click Applications from the sidebar and open the Utilities folder.
- Double-click the Terminal icon to launch it.
Another way to open this application is through Launchpad. To do that, simply press F4 on your keyboard and then type Terminal in the search field on the top.
Also, before you start using Terminal on your Mac for data recovery purposes, make sure that the application has full disk access. To do that, go to System Preferences > Security & Privacy and click Full Disk Access from the sidebar on the left. If Terminal isn’t on the list, click the plus icon to add it.
How to Recover Deleted Files Using Mac Terminal
Here are the most effective ways you can use Terminal to restore deleted files from your Mac.
Method #1: Recover Permanently Deleted Files With Recovery Tool
If you want to recover permanently deleted files on Mac using Terminal, your best option is to run a specialized data recovery tool with it and then restore the data using that tool. We’ll show you how to do this with two data recovery tools: Disk Drill and PhotoRec.
Option A: Disk Drill
Our recommendation is Disk Drill since it provides fascinating results in no time and is incredibly easy to navigate. Moreover, it’s compatible with the newest macOS X versions and supports a wide range of file formats and file systems. For more info on the tool, check out our in-depth Disk Drill review.
To download Disk Drill, go to the CleverFiles official website and click the link. Then follow the onscreen instructions to install the application.
And if you for any reason need to open this tool through Terminal, you can definitely do that, just follow these steps:
- Launch the Terminal application on your Mac.
- Copy-paste the following command line into Terminal:
/Applications/Disk\ Drill.app/Contents/MacOS/Disk\ Drill
- Hit Return.
- Once the tool has launched, choose the drive containing the deleted data and click Search for lost data to initiate the scan.
- Wait for the scan to finish and click the Review found items to look through the discovered data.
- Use the search field at the top right corner to find the needed file, or click a specific tab on the sidebar on the left to narrow down your scan results.
- Select the files that you wish to recover and click the Recover button.
- Choose a preferred destination for the recovered data and click OK to confirm.
Option B: PhotoRec
Follow these steps to use Terminal to run PhotoRec and recover your deleted files:
- Download PhotoRec and TestDisk (you can’t download these two applications separately).
- Open Terminal.
- Type in the following command and hit the Return key:
- Use the arrows on your keyboard to choose the needed disk. Hit Return to confirm.
- Choose the filesystem type where the deleted files used to be located.
- Select Free to scan for the deleted files or Whole to recover the data from the whole partition.
- Choose a folder on your Mac that you wish to use as the destination for the recovered data and hit the C key to confirm.
Method #2: Search for Deleted Files In Mac’s Temporary Files Folder
Temporary folders on your Mac contain various cache and temp files. Such folders are hidden on your computer and can’t be manually found by the users. Therefore, if you think that the file that you’re searching for might be in one of those folders, the quickest way to access them will be through Terminal.
Follow these steps to access the Temporary Files Folder on your Mac via Terminal:
- Open the Terminal app on your computer.
- Type in the following command line and hit the Return key:
- Open the Temporary folder by typing this command and hit Return to confirm:
- Once you’ve located the needed file, drag and drop it to a different folder.
Method #3: Recover Deleted Items From Trash
Basically, Trash is just another folder on your Mac (but with a special purpose). Once you delete a file from your computer, it first gets moved to this folder, and only after you empty Trash, the data get permanently erased.
There are two ways to access the Trash folder: without software (by clicking the Trash icon on the Dock) or through the Terminal app if the first option, for some reason, doesn’t work. And you’ll be able to both preview the files located there and even recover deleted folders on Mac using Terminal from Trash.
Follow these steps to recover deleted files on Mac using Terminal from Trash:
- Open Terminal.
- Type the following command and hit Return:
- Copy-paste or type the following command to look through the names of the files loaded in the Trash folder:
ls -al ~/.Trash
- Hit Return.
- To restore a file back to its original location, type in the following command and hit Return:
mv filename …/ (replace filename with the corresponding one)
- Quit Terminal.
To view the recovered file, go to the folder where the file used to be located before deletion.
Method #4: Recover Deleted Files Using Time Machine
You might be wondering, why not just launch the Time Machine app on your Mac and complete the data recovery process from there? The truth is, doing it through Terminal can be incredibly helpful, especially in cases when your mouse isn’t working or when you simply can’t restore the deleted data from a Time Machine backup because the app won’t launch.
Here’s how to recover deleted files on Mac in Terminal with the help of Time Machine:
- Connect the drive containing your Time Machine backups to your computer (if they are located on an internal drive, skip this step).
- Launch the Terminal app on your Mac.
- Type in the following command and hit the Return key:
- Use this command as the basis for the one that suits your data recovery needs:
tmutil restore ‘backup_path/original_path’ ‘~ destination’
The best way to recover permanently deleted files is with a tool like Disk Drill. Here’s what you should do:
- Download and install Disk Drill for Mac.
- Launch the app and choose your Mac’s drive.
- Initiate the scan.
- Choose the needed files and click Restore.
- Select a preferred folder for the recovered files.
It depends on your specific data loss situation, and sometimes not much can be done to undo the trouble. However, if not much time has passed since you’ve deleted the file on your Mac with the rm command, you should be able to recover the data with the help of a specialized data recovery tool (for example, using Disk Drill). But in some more complex cases, you might need to resort to a data recovery center.
Unfortunately, it’s almost impossible to recover emptied Trash through the Terminal app on your Mac since this command-line application is just a replacement for the graphical user interface of the Trash folder. But Terminal can be used to launch or use other specialized data recovery tools (like Disk Drill) that can help restore files from the emptied Trash.
There are many Mac data recovery Terminal commands. But depending on your data loss situation, you might need to modify the command to meet your specific recovery needs. Here are some examples of Terminal data recovery commands:
- cd .Trash — starts the recovery process of the Trash folder.
- mv filename …/ — restores a file from Trash.
- tmutil listbackups — shows available Time Machine backup versions.
- open $TMPDIR — opens the Temporary files folder.
As you can see, there’s nothing complicated in using the Terminal app on your Mac to recover deleted files. Even though the tool doesn’t have a graphical user interface, it’s quite simple to navigate when you know which commands to use.
But unfortunately, Terminal has some downsides and isn’t capable of recovering missing data in more complex data loss situations. If that’s your case, keep in mind that you have other amazing options (for example, restoring the needed files with the help of a data recovery tool like Disk Drill)