Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Utilize the trash from the Terminal UNIX
Since the "Trash" is just another folder on the filesystem, from the Terminal you can send items to the trash instead of deleting them by simply issuing a mv file_or_folder_name ~/.Trash/ instead of using rm file_or_folder_name, which permanently deletes things.

[robg adds: Yes, this is a simple hint ... but if using rm in the Terminal makes you a bit apprehensive, mving those items to the trash instead will give you one more level of safety.]
    •    
  • Currently 2.80 / 5
  You rated: 2 / 5 (5 votes cast)
 
[7,851 views]  

Utilize the trash from the Terminal | 8 comments | Create New Account
Click here to return to the 'Utilize the trash from the Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Utilize the trash from the Terminal
Authored by: wgscott on Sep 13, '05 11:15:16AM
Have a look at Gary Kerbaugh's rrm script:

[ Reply to This | # ]
Iv'e done this and had some problems.
Authored by: SOX on Sep 13, '05 11:16:04AM
the trouble with this hint is that it does not quite handle the possible flags on rm gracefully. in particular rm -r. instead you could alias it to a perl script.

perl -wane 'foreach  (@F) { system("mv",$_, "~/.trash") unless  m/^-/ } '
this script just silently removes any command line argument begininng with a "-". It will of course fail for any file whose name really does start with a dash.

[ Reply to This | # ]
Utilize the trash from the Terminal
Authored by: fds on Sep 13, '05 12:06:55PM

Then of course it's still a bit more complex than that.

Consider the case when there's already a file of the same name in your Trash folder as the one you are trying to move there.
Without the -i switch, mv will silently overwrite the old copy.



[ Reply to This | # ]
Utilize the trash from the Terminal
Authored by: wgscott on Sep 13, '05 12:18:34PM

Gary's script handles this.



[ Reply to This | # ]
Utilize the trash from the Terminal
Authored by: mesa on Sep 13, '05 12:37:14PM

trash, which is a part of the osxutils package, behaves like finder but from the command line. osxutils is available via fink or
http://sourceforge.net/projects/osxutils

/Michael

---
This space intentionally left non-blank



[ Reply to This | # ]
Script does not operate as advertised.
Authored by: SeanAhern on Sep 13, '05 03:55:48PM

I just checked out the 'trash' script from that package. It does <i>not</i> operate like the Trash, only from the command line. The script merely moves the file to the ~/.Trash folder, checking to make sure the subpath names are created. But what it does not do is check to see if there is a name collision. That is, it does not check if it would be overwriting an existing file in the trash. That's a serious omission. In addition, it only uses the UNIX 'mv' command, rather than using CpMac or ditto or something else.

I would instead use the rmm script quoted above.



[ Reply to This | # ]
Utilize the trash from the Terminal
Authored by: boredzo on Sep 13, '05 08:57:59PM

this post requires member access.



[ Reply to This | # ]
Utilize the trash from the Terminal
Authored by: cobalty on Sep 14, '05 03:52:59AM

yea that was strange, I really hope that macosxhints doesn't move to this model. There are several websites I just stoppped bothering with becuase I didn't feel like logging in eveytime I opened one of their articles using my news reader. This was even more of a pain because i'd have 50 windows open and not even remember what the article that I was supposed to read was about so i'd just close the window. PLEASE say it isn't so.



[ Reply to This | # ]