Accidentally deleted everything from a directory on my Macbook using terminal

Restoring from backup is the way to go here, there is no magic „undo rm -rf“ command.


You do not need to restore your whole machine. You need to restore only one folder. Time machine is much faster than I assume. Seems like a big deal to me since I've been trained never to relay on backup.

Just crank up Time Machine and copy the folder, in which you deleted all the content, back to where ever you had it. I had to go back a level in TimeMachine's display before the restore button became active.

Of course, you you could be missing the absolute latest changes.

enter image description here

Pick what folder you want to restore. I picked my numbers folder.

enter image description here

result: enter image description here

PS: I do not recommend deleting directories from the terminal. It's safer from finder. I've added the following aliases to my bash profile.

alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'

Run these command and see how they go. When you delete all the files in a directory with the rm command, you will get asked to approve each file to be deleted. Once you have establish rm is deleting the correct files, use control + c to quit. Then repeat with a backslash \ in front of the rm command to nix the alias version of the command and go to the plain rm command. As a warning, aliases do not cross over to commands with a proceeding sudo. Be careful.

In my account profile I've enhanced the cd command to print out the directory I cd'd into. This reduces slightly the risk of me getting confused over what directory I am in.

# Print current directory after change directory command cd
alias cd='cdir'

# Define a command to change a directory and list the resulting directory
function cdir ()

{

  \cd "$*"
  pwd

}