How to Recover Deleted Files or Folders with Mac Terminal: Sonoma Compatible

avatar
Connie Wisley
October 19, 2023 Preview 4.7K Preview 1
share it facebook share it Twitter

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. One of the Terminal’s useful features is to recover deleted files and here we will focus on the step-by-step guide to recover files or folders using Mac Terminal.

Also, we have some Terminal recovery basics for you, so you can decide when and how to use Terminal for a higher recovery rate. In the latter part of this post, we offer solutions when Terminal not working in some cases, like restoring files deleted with Terminal rm command.

 

The Basics: What is Terminal and How It Delete Files?

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 file type, delete files, recover files, etc.

Mac Terminal can delete files with rm command, you just need to type rm in Terminal and leave a space , then drag the file to Terminal and press Enter key to delete the file. But you won’t be able to retrieve this deleted file in your Mac Trash bin after running rm command on your Mac, because Terminal rm deletes a file permanently, there is no way to revert, unless you have installed a professional data recovery program.

delete file terminal

 

Can Mac Terminal Recover Permanently Deleted Files?

No, Terminal cannot recover a permanently deleted file.

It can delete a file permanently, but speaking of Terminal recovery, it only applies to recovering files moved to Mac Trash bin, and you cannot recover deleted files using Mac Terminal in following cases:

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

But luckily, we have ways to recover permanently deleted files that erased by Terminal rm command, in part 4, you will find the solution with steps.

 

How to Recover Deleted Files or Folders with Terminal on Mac

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

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 following.recover deleted file terminal01
  3. Input mv filename ../, then press Enter, your Terminal interface will be as following, the filename should contains the file name and file extension of the deleted file, also there should be a space after the file name.recover deleted file terminal02
  4. If you cannot find the deleted file, search with the file name in the search bar and save to wanted folder. My recovered file is under the home folder.recover deleted file terminal

 

Recover Multiple Deleted Files Using Mac Terminal

  1. Launch Terminal on your Mac.
  2. Input cd .Trash, press Enter.recover deleted files terminal01
  3. Input ls to list all files in your Trash bin.recover deleted files terminal02
  4. Check all files in your Trash bin.recover deleted files terminal03
  5. Input mv filename, copy and paste all file names for the files you want to recover, divide these filenames with a space.recover files terminal04
  6. Then find the recovered files in your home folder, if you cannot find the recovered files, search with their file names.recover deleted file terminal05

 

Recover Deleted Folder Using Mac Terminal

  1. Launch Terminal on your Mac.
  2. Input cd .Trash, press Enter.
  3. Input mv foldername ../, then press Enter, your Terminal interface will be as following.recover folder terminal 01
  4. Find the deleted folder under home folder and move to the location as you need.recover folder terminal 02

 

How to Recover Files that Permanently Deleted by Terminal?

As we mentioned at the beginning of this post, Terminal only works on recovering deleted files in Trash bin, it doesn’t work when a file is permanently deleted, no matter 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 files permanently deleted with Terminal rm command line on Mac, that is, using Cisdem Data Recovery for Mac.

Cisdem 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 drive, external hard disk, USB, SD Card, media players, etc. It can read and recover 200+ types of files, including videos, audios, photos, documents, archives and others. 

Cisdem Data Recovery Main Features

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

How to Recover Files Permanently Deleted by Terminal rm on Mac

  1. Download and install Cisdem Data Recovery.
     Free Download macOS 10.9 or later
  2. Go to Hardware Disk, choose the drive where you deleted the files and click Search for lost files to start the scanning.cisdem recover deleted files 02
  3. Go to Type, all the recoverable items will be stored in different folders, you can filter by file type, size, date, or just enter a keyword in the search box to quickly locate files.cisdem recover deleted files 03
  4. Double click the files to preview, then select them and click Recover to restore all the permanently deleted files to your Mac.  recover deleted files mac04

 

Other Solutions When Mac Terminal Not Working on Recovering Files?

Mac Terminal may not 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 Trash bin if Terminal not working.

Method 1. Put Back from Trash Bin

  1. Open Trash bin app.
  2. Find the files you want to recover, right click and choose "Put Back". recover files by put back
  3. Then check the recovered file in the original storage folder or search with 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, 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. recover deleted files time machine

 

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 home folder. But due to its limitation to recover files moved to Trash bin only, we highly recommend you using Cisdem Data Recovery to recover any deleted files, no matter it is temporarily deleted, or permanently deleted.

avatar
Connie Wisley
share it facebook share it Twitter

Connie has been writing for Mac productivity and utility apps since 2009. Each review and solution is based on her practical tests, she is aways energetic and trustworthy in this field.

share it facebook share it Twitter
Comments (1) Leave a Reply

Name *

Comment *

  • Donna Byrd

    It does work, I followed your steps and recovered batches of files, for a file name with spaces, we need to add \, this is very important and the lesson I learned. Thanks.

    0 months ago commonReply

    Name *

    Comment *

Hot Articles

How to Backup Mac including MacBook Pro How to Format SD Card on Mac, Windows, Android and Camera Microsoft Word Not Responding on Mac? How to Save and What to Do
Home > How to Recover Deleted Files or Folders with Mac Terminal: Sonoma Compatible