3 Simple Ways to Recover Files Deleted by Command Line on Mac

Jean updated on Jan 22, 2021 to Mac File Recovery | How-to Articles

Files on Mac can disappear if you use rm/srm command. For recovering lost files from rm command, there are three available ways you can try. The first is to use the Mac undelete command line to recover delete files in Mac terminal; the second way is referring to Time Machine backup if you have created before; and the last, also the easiest and safest way is to use the professional EaseUS Data Recovery Wizard for Mac to retrieve deleted/lost files on Mac in three steps.

Deleted files on Mac by using rm command. How to recover?

"I accidentally deleted a file by running "rm -rf ./Desktop/myScript.sh". I think there might be some ways to recover files deleted on Mac OS X since rm command only removes files temporarily. But I don't know how to make it? What's your suggestion?"

Here, you'll learn three ways to recover the command line deleted files. Choose any one of the methods to recover deleted files now:

Workable Solutions Step-by-step Troubleshooting
Fix 1. Undelete with Terminal Command Go to "Applications" > "Utilities" > double-click on "Terminal" to open the application > type cd .Trash...Full steps
Fix 2. Restore with Backup on Mac Connect the Time Machine backup disk to your Mac and turn it on > find files and select...Full steps
Fix 3. Restore files with software Download EaseUS file recovery software for Mac > select the location > scan...Full steps

A Brief Overview of rm Command Line 

rm command simply deletes the directory entry for the file while leaving the disk blocks it used, untouched. You can try to re-discover those blocks contents with some advanced methods. The essential issue is that nothing else re-uses any of the disk blocks represented by your file.

How to Recover Files Deleted by Command Line on Mac

If you have performed a quick deletion with the rm command line to mistakenly remove some needful files from the desktop or anywhere else on Mac, the files won’t go to the trans bin, so you can't recover the lost files from trash bin directly. But don't worry, you can still use the advanced methods below to recover deleted files by command line possibly.

Method 1. Undelete Files with Terminal Command on Mac 

1. Go to "Applications" > "Utilities" > double-click on "Terminal" to open the application.

2. Type in the following Terminal command: cd .Trash, then hit the "Return".

3. Type mv xxx ../. Replace the "xxx" part with the full name of the file you deleted. Hit the "Return" key.

4. Type Quit in the Terminal window.

5. Launch the "Finder" window. Enter the name of the deleted files in the search bar at the top right part of the window to find the restored files.

Note: You must type the Terminal commands exactly, otherwise, the data recovery will fail.

Method 2. Restore with Time Machine Backup on Mac

Only users with backups can apply to this solution. If you haven't made any backup before, jump to the next part to recover deleted Mac files with the user-friendly EaseUS Data Recovery Wizard for Mac.

Time Machine, the built-in backup feature of your Mac, to automatically back up all of your files, including apps, music, photos, email, documents, and system files. With the backup, Mac deleted file recovery from the command line will be easily settled.

1. Connect the Time Machine backup disk to your Mac and turn it on.

2. Find the files you want to restore in your Time Machine backup. Select a item and press Space Bar to preview it and make sure it's the one you want.

3. Click "Restore" to recover the items you selected.

Method 3. Restore Mac Deleted Files with a Data Recovery Tool Without Backup

If you're not familiar with the command line, neither have a Time machine backup, a Mac data recovery program is your best choice. EaseUS Data Recovery Wizard for Mac not only can help recover files deleted by command line but also restore lost files from formatted hard drive/partition on Mac, virus infection, system reinstallation and more. Follow the three steps below to see how to make it in the easiest and quickest way. 

Step 1. Select the location where your important data & files were deleted and click the "Scan" button.

select the location where data was deleted and click scan

Step 2. The software will run both quick scan and deep scan and work hard to find as many deleted files as possible on the selected volume.

scan the selected disk to find deleted files on your Mac

Step 3. The scan results will be displayed in the left pane. Just select the file(s) and click the "Recover Now" button to get them back.

click recover now button to recover deleted files on your Mac

Was This Page Helpful?


Frequently Asked Questions

1. Why choose EaseUS Data Recovery Wizard?

"EaseUS Data Recovery Wizard is the best we've seen. It's far from perfect, partly because today's advanced disk technology makes data-recovery more difficult than it was with the simpler technology of the past, but it's fast and efficient..."PCMag

"The first thing you'll notice about EaseUS Data Recovery Wizard Pro is that its interface is very clear and uncluttered, with only a small collection of self-explanatory controls. You won't find lots of extra options hidden in a system of hidden menus, either; what you see really is what you get."techradar

"Recover lost files, even after deleting a partition or formatting your drive."Macworld

2. Why cannot I recover 2GB data for free?

It is recommended to check the version installed is Free or Trial because they are different versions.

Trial has data preview function but cannot save any files, while the Free version enables to recover 2 GB files. The default free space is 500 MB and you may share the product on social media to get another 1.5 GB.

3. Why cannot the recovered files be opened?

A file is saved as 2 parts on the storage device: directory info (which is comprised by file name, time stamp and size info, etc.) and data content.

If the files with original file names and folder structures cannot be opened, one possible reason is the corrupted directory info. There is still a chance to recover the data content with the RAW Recovery method in our software.

4. Why isn't it suggested to recover the files back to the original drive?

The storage structure of the lost files would be altered or damaged by any changes on the drive. If you save the recovered files back to the same drive, the original data structures and data content would be corrupted or overwritten, which causes permanent data loss. So you should prepare another disk to save the files.

5. How can I check whether my data is recoverable or not before purchase?

The Free version helps you save 2GB files, so verify the recovery quality of our product before purchase.

6. How long does it take to scan the drive?

It strongly depends on the capacity of your hard drive and the performance of your computer. As reference,most drive recoveries can be completed in around 10 to 12 hours for a 1-TB healthy hard drive in general conditions.

About Data Recovery Wizard

It's super easy to recover 250+ types of files after deletion, disk formatting and virus infection. Click the links and compare the difference of each version.