How to Recover Deleted Files Using Mac Terminal Command Line

How to Recover Deleted Files Using Mac Terminal Command Line: Step-to-Step Guide

If you are familiar with command lines, you may prefer to perform tasks with Mac Terminal, because it allows you to make changes on your Mac quickly even once and for all. One of Terminal’s useful features is to recover deleted files and here we will focus on the step-to-step guide to recover files using Mac Terminal.

Also, we have some Terminal basics for you, to help you have a better understanding of the Terminal. In the latter part of this post, we offer solutions for data loss scenarios when the Terminal not working, for restoring files deleted with the Terminal rm command.

What are Terminal and Things You Need to Know about Terminal Recovery

The terminal is the macOS command line application, with a collection of command shortcuts, you can perform different tasks on your Mac quickly and efficiently without repeating certain actions manually.

You can utilize Mac Terminal to open an application, open a file, copy files, download files, change location, change the file type, delete files, recover files, etc.

Speaking of Terminal Recovery, it only applies to recovering files moved to the Mac Trash bin, and you cannot recover deleted files using Mac Terminal in the following cases:

  • Delete files by emptying the Trash bin
  • Delete files by right-clicking on Delete Immediately
  • Delete files by pressing the “Option+Command+Backspace” keys
  • Delete files using Mac Terminal rm (permanently delete files) command: rm, rm-f, rm-R

How to Recover Deleted Files Using Mac Terminal

If the deleted files are just moved to your Trash bin, instead of being permanently deleted, you can restore them using Mac Terminal, to put the deleted file in the Trash folder back to your home folder. Here we will offer a step-to-step guide to recover one or multiple files using the Terminal command line.

How to Recover A Deleted File Using Mac Terminal

  1. Launch Terminal on your Mac.
  2. Input cd .Trash, then press Enter, your Terminal interface will be as follows.
    How to Recover Deleted Files Using Mac Terminal Command Line: Step-to-Step Guide
  3. Input mv filename ../, then press Enter, your Terminal interface will be as follows, the filename should contain the file name and file extension of the deleted file, also there should be a space after the file name.
    How to Recover Deleted Files Using Mac Terminal Command Line: Step-to-Step Guide
  4. If you cannot find the deleted file, search with the file name in the search bar and save it to the wanted folder. My recovered file is under the home folder.
    How to Recover Deleted Files Using Mac Terminal Command Line: Step-to-Step Guide

How to Recover Multiple Deleted Files Using Mac Terminal

  1. Launch Terminal on your Mac.
  2. Input cd .Trash, press Enter.
    How to Recover Deleted Files Using Mac Terminal Command Line: Step-to-Step Guide
  3. Input ls to list all files in your Trash bin.
    How to Recover Deleted Files Using Mac Terminal Command Line: Step-to-Step Guide
  4. Check all files in your Trash bin.
    How to Recover Deleted Files Using Mac Terminal Command Line: Step-to-Step Guide
  5. Input the mv filename, copy and paste all file names for the files you want to recover and divide these filenames with a space.How to Recover Deleted Files Using Mac Terminal Command Line: Step-to-Step Guide
  6. Then find the recovered files in your home folder, if you cannot find the recovered files, search with their file names.
    How to Recover Deleted Files Using Mac Terminal Command Line: Step-to-Step Guide

What if Mac Terminal Not Working on Files Recovery

But Mac Terminal doesn’t work sometimes, especially when the file name of a deleted file contains irregular symbols or hyphens. In this case, there are 2 options to recover deleted files from the Trash bin if the Terminal not working.

Method 1. Put Back from Trash Bin

  1. Open the Trash bin app.
  2. Find the files you want to recover, right-click, and choose “Put Back”.
    How to Recover Deleted Files Using Mac Terminal Command Line: Step-to-Step Guide
  3. Then check the recovered file in the original storage folder or search with the file name to find out its location.

Method 2. Recover Deleted Files with Time Machine Backup

If you have enabled Time Machine to back up your files on a regular schedule, you can utilize its backup to restore deleted files too.

  1. Launch Time Machine and enter.
  2. Go to Finder>All My Files, and find the deleted files you want to recover.
  3. Then use the timeline to select the wanted version for your deleted file, you can press Space Bar to preview the deleted file.
  4. Click Restore to recover deleted files on Mac.
    How to Recover Deleted Files Using Mac Terminal Command Line: Step-to-Step Guide

Easiest Way to Recover Files Deleted with Terminal rm on Mac

As we mentioned at the beginning of this post, Terminal only works on recovering deleted files in the Trash bin, it doesn’t work when a file is permanently deleted, no matter if it is deleted by “deleted immediately” “Command+Option+Backspace” “Empty Trash” or “rm command line in Terminal”. But no worries, here we will offer the easiest way to recover deleted files deleted with the Terminal rm command line on Mac, that is, using MacDeed Data Recovery.

MacDeed Data Recovery is a Mac data recovery program to restore deleted, lost, and formatted files from both internal and external drives, for example, it can recover files from Mac internal hard drives, external hard disks, USBs, SD cards, media players, etc. It can read and recover 200+ types of files, including videos, audio, photos, documents, archives, and others.

MacDeed Data Recovery Main Features

  • Restore deleted, lost, and formatted files apply to data loss under different situations
  • Recover files from Mac internal and external hard drive
  • Recover videos, audio, documents, archives, photos, etc.
  • Use both quick and deep scan
  • Preview files before recovery
  • Search specific files quickly with the filter tool
  • Fast and successful recovery

How to Recover Files Deleted with Terminal rm on Mac

Step 1. Download and install MacDeed Data Recovery.

Try It FreeTry It Free

Step 2. Choose the drive where you deleted the files, it can be Mac internal hard drive or an external storage device.

Select a Location

Step 3. Click Scan to start the scanning process. Go to folders and find the deleted files, preview before recovery.

files scanning

Step 4. Check the box before the files or folders that you want to recover, and click Recover to restore all deleted files to your Mac.

select Mac files recover

Conclusion

In my test, though not all deleted files can be recovered by using Mac Terminal, it does work to put back the files I moved to Trash to the home folder. But due to its limitation to recover files moved to the Trash bin only, we highly recommend you use MacDeed Data Recovery to recover any deleted files, no matter if it is temporarily deleted, or permanently deleted.

Recover Files If the Terminal Not Working!

  • Recover temporarily deleted files
  • Recover permanently deleted files
  • Recover files deleted by the Terminal rm command line
  • Restore videos, audio, documents, photos, archives, etc.
  • Preview files before recovery
  • Quickly search files with the filter tool
  • Recover files to a local drive or cloud platforms
  • Apply to different data loss

Try It FreeTry It Free

How useful was this post?

Click on a star to rate it!

Average rating 4.5 / 5. Vote count: 2

No votes so far! Be the first to rate this post.