With how much we use our Macs, we’re constantly adding new data to them but at the same time, deleting things that we don’t need anymore. Sometimes we may delete something only to then realize that we weren’t finished with it and that we wished we would have kept it a little bit longer.

While there are multiple ways to recover data on your Mac, in this article we’re going to take a look at how to recover deleted files on Mac using the Terminal. If you would like to use something with a graphical interface, we’re going to take a look at an option that will allow you to do it that way as well.

What Is the Mac Terminal and How Does It Work?

The Terminal provides text-based access to the operating system, in contrast to the mostly graphical nature of the user experience of macOS.

With this text-based interface, you can access shells or other aspects of the operating system at a deeper level and it will allow you to do some tasks that can’t be done with the normal graphical interface.

Now that we know what the Terminal is, let’s talk about how to launch and use it.

How to Launch Terminal on Mac

Launching the Terminal is actually quite easy and it comes built-in as part of the operating system on macOS so you don’t need to download anything to open the app.

Step 1. Launch Finder and go to Utilities.

utilities-folder-in-finder

Step 2. From within Utilities, look for the Terminal app and double-click on it to launch it.

launching the terminal from within finder

Step 3. You will then be greeted by a new blank Terminal window where we can type commands into the Terminal.

blank terminal window

There are various ways to recover files using the Terminal and we’re going to take a look at some below.

How to Use the Terminal to Recover Deleted Files From the Trash

The Trash is where deleted files go. Files are either put into the trash or you can delete them permanently right away.

You will need to change your privacy settings so that the Terminal can have Full Disk Access before the steps below will work. Don’t worry though, this is super easy to do and will only take a few steps.

Step 1. Launch your System Preferences and then navigate to the Security & Privacy tab.

Step 2. From within here, you will want to look for Full Disk Access and allow the Terminal full access to your Mac.

system preferences terminal

Step 3. Now we can Launch the Terminal. This can be done by going to the Finder and then your Utilities folder. You can learn how to launch the Terminal by reading the steps above.

Step 4. Now that you’re greeted with a new Terminal window, we can start recovering deleted files.

Step 5. The first thing that we want to do is navigate to the trash folder so that we can view its contents. Type in the code below and then hit return:

cd .Trash

Step 6. Next, we want to bring up the contents of the trash which can be done by typing in the code below and then hitting return.

ls -al ~/.Trash

viewing the trash in the terminal

Step 7. We can recover deleted files by typing in the following with the correct path and then hitting return:

mv filename ../

I went skiing recently and deleted a picture so what I can do to recover it is type in mv and then I went to the Trash and dragged the file into the Terminal as this will type out the pathname for me. I have posted the file name below to give you an idea of how it will look. After you have typed out the file name, click return on your keyboard.

/Users/joellockard/Library/Mobile\Documents/com\~apple\~CloudDocs/.Trash/brighton-sunset-mountain.jpeg ../

Step 8. After the file has been recovered, go to your home directory folder to view the recovered file.

Recovering Deleted Files From External Devices Trash

External devices such as thumb drives have their own local trash installed on them. These files are hidden by default so that users don’t make changes to them. We can look into them though to check for deleted files. I go into more depth on this in an article where I talk about external hard drive recovery.

Step 1. Press the keys SHIFT + CMD + . to enable hidden files. You can also enable hidden files and folders by launching the Terminal and typing in:

defaults write com.apple.finder AppleShowAllFiles TRUE

and then type in:

killall Finder

Now we will be able to see the folder below:

.Trash

Step 2. Now that you have run these commands, you should be able to view the contents of the trash folder. Simply browse the folder for any files that you would like to recover.

Now let’s take a look at how to run Time Machine from the Terminal. Time Machine allows you to backup your Mac and recovers data from it which is something that I would highly recommend that you do.

Running Time Machine via the Terminal

Time Machine is a built-in backup utility that allows you to back up your Mac to an external hard drive. Most of the time, you can use the Time Machine interface instead of the Terminal for recovering deleted files.

The Terminal-based method can come in handy if you’re trying to control Macs that are remote or if you’re running scripts on them. You could also use this recovery method to learn how to run Time Machine without using the graphical interface.

Most of the Time Machine commands will have the following in their name:

tmutil

Step 1. Launch the Terminal. Make sure that the Terminal has full disk access which is explained in the section above.

Step 2. Type in the following to list all of the time machine backups that you have available:

tmutil listbackups

time machine backups in the terminal

Step 3. Type in:

tmutil restore ‘$BACKUP_PATH/$ORIGINAL_PATH’ ‘$DESTINATION’

This will allow you to restore a file from your Time Machine backup. Remember that you will need the entire path when you put in the name of the file.

If all of those Terminal and text-based are getting you excited, there are entire data recovery tools that run within the Terminal.

Command-Line Recovery Software Option for Mac

PhotoRec is a command-line tool that allows you to recover deleted files and I would highly recommend it. While there is a lot to go into when it comes to talking about PhotoRec, I would recommend taking a look at a review and walkthrough that I did of it in the past. You can check out the review here.

selecting media in photorec

You can read more about PhotoRec here and can download it by clicking here.

Are There Any Data Recovery Software Alternatives With a Graphical User Interface?

After learning about the Terminal and PhotoRec, you may decide that you still want to use a recovery option that includes a graphical user interface. The good news is that Disk Drill is a great option when it comes to data recovery.

Disk Drill can recover deleted files on your Mac and other devices. It does this by scanning your hard drive for data that is not visible to you but is still located on your hard drive.

Using Disk Drill just requires you to download and install the software and then from there, you can scan your machine and start recovering deleted files.

Step 1. Download and install Disk Drill.
Step 2. Select the storage device that you would like to scan. Disk Drill can also recover data from external hard drives as well.

selecting external hard drive in disk drill

Step 3. Wait for the scan process to complete.

scan in progress

Step 4. Browse through the contents and checkmark the items that you would like to recover. You will then want to click the blue Recover button in the lower right-hand corner of the screen.

recovering data from within disk drill

Step 5. After clicking on Recover, you will then have to choose a recovery destination for the files to be saved to.

Conclusion

The Terminal can seem quite scary when using it for the first time but as you can see, it’s not that hard to use and most things only require a few lines of text to be typed in before you can recover deleted files.

I always love knowing more than one way to do something as sometimes one way may make more sense than the other. Being more comfortable with the Terminal will make you an overall better Mac user and even if you don’t want to use it, you can always go back to using the graphical interface. Either way, you learned something new.