If you just accidentally deleted a file on your Mac, you have several ways to go about recovering that information.

One of the fastest options is to use the Mac Terminal. By typing specific command lines, you can restore the missing information in literally seconds.

recover deleted files mac terminal

You can also use third-party software solutions from data recovery companies to recover the accidentally deleted files.

This guide will take you through the processes to follow so that you can restore your files.

Quick Guide to Available Recovery Methods

Data loss situation:

Suitable recovery method:

An important file has recently been deleted.

Restore deleted files from Trash by using Mac Terminal

An important file has been deleted some time ago or isn’t present in the .Trash folder anymore.

Recover deleted files with data recovery software

You failed to recover lost files from the .Trash folder, and the files were not found by data recovery software.

Use a recent Time Machine backup

You need to recover files from a damaged or missing partition.

Restore lost partitions with TestDisk

What Is Mac Terminal and How Does It Work?

Mac Terminal is a command line emulator you can access on all macOS systems. It allows you to take control of your computer quickly to make specific changes.

You can locate it using the Spotlight feature on your Mac, through Finder, or via Launchpad and your Utilities icon.

recover deleted files mac os terminal

If you’re familiar with MSDOS or UNIX operating systems, the emulator functions similarly. Even most of the commands are the same, although you’ll see more periods than frontslahes or backslashes in each one.

How to Recover Deleted Files Using Mac Terminal

When you need to recover deleted files quickly, Mac Terminal is one of the best options to choose. These four techniques can help you have a successful experience.

Method 1: Restore deleted files from Trash by using Mac Terminal

  1. After opening Terminal through your Utilities on Mac, type the following command: cd .Trash, then hit Return.
  2. You’ll now type ls -al ~/.Trash to view the contents of your Trash folder. 
  3. Now type mv filename ../ and hit Return again. You must use the full file name in the command line for this technique to work.
  4. Type “Quit“. This command exits terminal.

mac recovery mode terminal commands

You should see the deleted file in Finder. If it doesn’t show up in the prompt window, use the search bar with its name to locate it.

Method 2: Recover deleted files with data recovery software.

You use the “RM” command to delete files,  it doesn’t permanently erase the information. The command allows you to disrupt the link to the file so that it is no longer findable while designating its space as writable.

Follow these simple steps to restore your deleted data.

  1. Follow these simple steps to restore your deleted data.
  2. Download and install Disk Drill.
  3. Launch the program and select the device that experienced the data loss.recover rm files mac with disk drill
  4. Click the Search for lost data button to scan the device.undo rm mac via disk drill
  5. Preview the found files and select those you want to recover.rm restore in disk drill
  6. Click the Recover button to complete the recovery.recover deleted rm files disk drill

Method 3: Restore lost partitions with TestDisk

When dealing with damaged or lost partitions, simple Terminal commands are not enough to save the day. What you need is specialized partition recovery and repair software like TestDisk, which runs directly in the Terminal app.

Before you can install TestDisk, you first need to install Homebrew, a free and open-source software package management system for macOS. To do that, just enter the following command in Terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

It then takes just one more command it install TestDisk itself: brew install testdisk

Even though TestDisk is a command-line software application, it offers a straightforward step-by-step data recovery process that can be summarized in just a few steps:

  1. Launch TestDisk by typing “testdisk” in Terminal.
  2. Select Create to create a new log file.testdisk log
  3. Select the storage device with the deleted partition.
  4.  Select the partition table type.
  5. Press Enter to analyze the current partition structure and search for lost partitions.Restore lost partitions with TestDisk
  6. Perform a Quick Search for the deleted partition.
  7. (Optional) Perform a Deeper Search to find deleted partitions that Quick Search wasn’t able to recover.

For detailed instructions on how to recover lost partitions and repair damaged boot sectors using TestDisk, read the official documentation

Method 4: Use a recent Time Machine backup

If the three data recovery methods described above has delivered the results you were hoping for, then there’s still some hope left because all Macs come with built-in backup software called Time Machine.

If Time Machine was active before the data loss incident took place, then it’s very likely that your files are safely backed up on your Time Machine backup disk, and  you can restore with a few clicks. 

recover deleted files mac time machine

Apple offers complete instructions to help you restore your Mac from a Time Machine backup.

If you haven’t initiated Time Machine before accidentally deleting your files, this recovery option is not available. You can turn it on for future efforts by following these steps.

  1. Go to the System Preferences menu select from your Apple menu.
  2. Select the Time Machine icon.
  3. Choose the “Select Disk…” command that you see in your macOS version.Select backup disk Time Machine
  4. Pick the external drive that you’d use for the Time Machine backup.select backup disk for time machine
  5. Tell Time Machine to back up your files automatically so that it runs in the background.Backup Files Automatically Time Machine

Once you have Time Machine keeping track of your files, it’ll provide download backups periodically to ensure your information stays relatively current.

When Won’t Mac Terminal Help to Recover Deleted Files?

The primary reason why Mac Terminal isn’t recovering a deleted file is that you’ve got its name incorrect. If you don’t provide an exact match, the system cannot identify and restore access to the information you want to recover. 

If you have the file name correct, there could be an issue with the commands used to create results.

Copying the commands from a website into Mac Terminal only works when the correct spacing and symbols get used. For example, you might have typed “cd.trash” instead of “cd .trash” to access that folder.

When you discover that the files aren’t returning as expected, a third-party software solution is your best option. Programs like Disk Drill for Mac can scan your drive, locate the files, and make it restorable in a few clicks.

You don’t need to worry about knowing the full file name precisely because the recovery software displays that information for you to see. A preview feature even lets you see if the information is what you hope to restore through these efforts.

Conclusion

When you want to recover deleted files on your computer, Mac Terminal is a useful resource. It can help you create find missing data, and provide immediate access to it once again.

It won’t work in every situation, so it is helpful to have third-party file recovery platforms available to use. Disk Drill for Mac provides a straightforward solution that quickly scans your drive, locates recoverable information, and makes your effort as painless as possible.

Jeff Cochin

Jeff Cochin is a data management and recovery expert. He also serves as a technical writer, testing and reviewing tech solutions in various fields.Jeff Cochin is a professional data management, warehousing and recove...

Read full bio
Avatar
Approved by
Brett Johnson

This article has been approved by Brett Johnson, Data Recovery Engineer at ACE Data Recovery. Brett has a Bachelor's Degree in Computer Systems and Network, 12 years of experience.