Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Move file to trash from Terminal

Move file to trash from Terminal
Thread Tools
Mac Elite
Join Date: Sep 2000
Location: Edmond, OK USA
Status: Offline
Reply With Quote
Jul 12, 2004, 12:49 PM
 
Is there a command-line way to get a file into the trash? Also, can I secure-delete the trash contents from the command line?
     
Mac Elite
Join Date: Dec 2001
Location: Atlanta, GA, USA
Status: Offline
Reply With Quote
Jul 12, 2004, 02:23 PM
 
To move a file to the trash:

Code:
mv <somefile> ~/.Trash/
To secure-delete a file, use srm. It works like "rm" but has more options for secure delete.
Mac Pro 2x 2.66 GHz Dual core, Apple TV 160GB, two Windows XP PCs
     
Mac Enthusiast
Join Date: Mar 2004
Status: Offline
Reply With Quote
Jul 13, 2004, 04:02 AM
 
I would suggest writing a shell script to do this automatically... so you could just use "trash foo"
     
Fresh-Faced Recruit
Join Date: Jan 2004
Status: Offline
Reply With Quote
Jul 13, 2004, 04:16 PM
 
Originally posted by Turnpike:
I would suggest writing a shell script to do this automatically... so you could just use "trash foo"
FWIW, I just added a trash() function to my start-up file--in my case, .zshenv.

trash() { mv "$@" ~/.Trash; }

Of course, you can tweak as necessary. For example, I use this to collect all the .mp3s and send to trash:

trashmp3() { find . -iname '*.mp3' -exec mv {} ~/.Trash \; }

I ain't no expert but it works for me ;-)

HTH,

Uber
     
Mac Elite
Join Date: Sep 2000
Location: Edmond, OK USA
Status: Offline
Reply With Quote
Jul 13, 2004, 08:38 PM
 
Thanks to everyone - I think what I will do is alias trash to move files into the trashcan, and also create an alias to secure emtpy the trash from the command-line - that should work well.

Thanks all!
     
Dedicated MacNNer
Join Date: Jul 2001
Location: NC
Status: Offline
Reply With Quote
Jul 16, 2004, 08:22 PM
 
&nbsp;&nbsp;&nbsp;Scripts to move items to trash have already been written. I call my own rmm because it emulates the behavior of rm. It supports all of the same options and responds in the same way. The main difference is that it moves the files to trash instead of unlinking them. It uses 'ditto" to make the move so that resource forks are preserved. That way, if you make a mistake and want to pull items out of trash, they will still have their resource forks. Otherwise, some files would be rendered useless by the move to trash anyway.

&nbsp;&nbsp;&nbsp;If you download the script, you should get the one called rmm. The page linked to above is a little out of date; the rmm script has been thoroughly tested.
Gary
A computer scientist is someone who, when told to "Go to Hell", sees the
"go to", rather than the destination, as harmful.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:09 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2