8

I sent a lot of files and directories from an external hard drive into the trash by mistake. All those files and directories had the same grandfather directory but not the same father directory. I can put back each item individually but can't put back when I select several items that are not sister files/directory. Note that no path has been changed since I deleted all those files and directories. Anyway, I am thinking about using Bash.

Is there a putback command in bash?

  • It is probably too late now, but for the future, if you accidentally delete, if you press CMD + Z, it will undo the delete and return the files to where they were. – AMR Jul 29 '15 at 0:48
  • Well... I'll definitely remember for next time! Thnks – Remi.b Jul 29 '15 at 0:49
  • If you mount Trash using cd ~/.Trash, does it still show the directory structure preserved if you do ls? – AMR Jul 29 '15 at 0:53
  • @AMR under ~/.Trash and ls I only see one file (which was deleted from my computer not from the external hard drive). If I copy-paste a file from the trash to the terminal to see the address I see something like /Volumes/Seagate\ 2TB/.Trashes/501/D31, where D31 is one directory I want to put back. I have no idea where the 501 comes from. I can't cd to /Volumes. – Remi.b Jul 29 '15 at 1:05
  • And sorry I was thinking of my USB flash drive which deletes into cd ~/.Trash, not to one in its own directory structure. – AMR Jul 29 '15 at 1:09
1

This solution works on a single file in Trash or multiple files deleted from within the same directory:

If it's not essential for you to use Terminal, you can forget all those bash, zsh, and all other typealot ways to do this. Just navigate to Trash and CMD + Backspace the files you want to put back.

If the deleted files come from different folders, then you can't use this shortcut to put them all back at the same time.

| improve this answer | |
  • Does that work on files from different directories? I tried to delete a few files and I can only use Put Back on all the files if they were from the same directory, otherwise I have to do them individually. – AMR Jul 29 '15 at 0:56
  • @AMR It just works. CMD + BSpace moves files to Trash and from Trash. – theoden8 Jul 29 '15 at 0:57
  • Doesn't work if the files are from different directories. Try it out. – AMR Jul 29 '15 at 0:59
  • 1
    @theoden CMD + Backspace seems to be a shortcut for right-click > Put Back. It works whenever I select only one item but not when I select multiple items. – Remi.b Jul 29 '15 at 1:09
  • 1
    @Remi.b, Okay, I gotta sleep. The only problem I see is that when i do cat .DS_Store in Trash folder it does not recognize the letters as ascii (cat .DS_Store | strings). If that is accomplished, it's really easy to parse the whole stuff using the list of files in trash in ls or find and a set of $FILEkjlfsdhkVolume/.../$FILE;fdjska. – theoden8 Jul 29 '15 at 2:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .