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 > macOS > rm = mv to .Trash?

rm = mv to .Trash?
Thread Tools
awaspaas
Mac Elite
Join Date: Apr 2001
Location: Minneapolis, MN
Status: Offline
Reply With Quote
Feb 16, 2003, 12:31 PM
 
Is there a way to override the standard rm command and instead have it move the item to .Trash like the Finder does?
     
VEGAN
Senior User
Join Date: Jun 2002
Location: UK
Status: Offline
Reply With Quote
Feb 16, 2003, 12:45 PM
 
Originally posted by awaspaas:
Is there a way to override the standard rm command and instead have it move the item to .Trash like the Finder does?
There might be problems... since `rm' can be given OPTIONS and so can be `mv' and I'm not sure if they are the same...

But you are looking for `alias' command that allow you define commands...
     
Boochie
Mac Enthusiast
Join Date: Mar 2002
Status: Offline
Reply With Quote
Feb 16, 2003, 12:46 PM
 
Alias the 'rm' command at the terminal prompt thusly:

unalias rm (to remove any existing aliases you may have on rm)

alias rm 'mv \!* ~/.Trash'

Voila!
     
Zim
Senior User
Join Date: Apr 2001
Location: Cary, NC
Status: Offline
Reply With Quote
Feb 16, 2003, 01:00 PM
 
Which is fine as long as you are in a shell that got that alias...

Made me wonder tho... In a true brute force method, one could replace /bin/rm with a script of the alias... but I suspect Apple's delete really goes back and calls /bin/rm, so this would render Trash un-empty-able...

can anyone confirm?

Mike
     
Boochie
Mac Enthusiast
Join Date: Mar 2002
Status: Offline
Reply With Quote
Feb 16, 2003, 01:12 PM
 
True enough. A more complete solution would be to place that command in your .cshrc file, assuming you're using tcsh or csh as your login shell. If you're using bash, the bash-equivalent command would go in .bashrc. Then any new shell you open would use the move-to-trash version of rm.

Originally posted by Zim:
Which is fine as long as you are in a shell that got that alias...

Made me wonder tho... In a true brute force method, one could replace /bin/rm with a script of the alias... but I suspect Apple's delete really goes back and calls /bin/rm, so this would render Trash un-empty-able...

can anyone confirm?

Mike
     
Moonray
Mac Elite
Join Date: May 2001
Status: Offline
Reply With Quote
Feb 16, 2003, 03:20 PM
 
Leave the binaries in /bin alone. Scripts expect them to be there with exactly that functionality.
Using an alias is the proper solution (as is TBYT )

-
     
Richard Edgar
Dedicated MacNNer
Join Date: Sep 2002
Status: Offline
Reply With Quote
Feb 16, 2003, 04:51 PM
 
Don't forget though that the default behaviour for mv is destructive.... ie if something called myFile already exists in the trash, then moving another file of the same name there is going to blitz the first.
     
Boochie
Mac Enthusiast
Join Date: Mar 2002
Status: Offline
Reply With Quote
Feb 16, 2003, 04:59 PM
 
alias rm 'mv -i \!* ~/.Trash'

Boy, my Unix is rusty!

Originally posted by Richard Edgar:
Don't forget though that the default behaviour for mv is destructive.... ie if something called myFile already exists in the trash, then moving another file of the same name there is going to blitz the first.
     
Richard Edgar
Dedicated MacNNer
Join Date: Sep 2002
Status: Offline
Reply With Quote
Feb 16, 2003, 07:18 PM
 
Boy, my Unix is rusty!
So are my shell escapes... will that combination ensure that all special characters get correctly passed down the line? Spaces are particularly important, since unexpected things could happen if they don't get escaped. What about if the command was a pattern match? Or worse, if one of the filenames contained wildcards? Remember "|", ";", "*", "!" and "\" are all perfectly legitimate characters to have in a filename - and great pain could result if they come up in a bad order. Such an order may be unlikely, but anything which is supposed to be robust and userfriendly must deal with all cases.

As a final thought, does mv know about resource forks?
     
int69h
Dedicated MacNNer
Join Date: Nov 2000
Status: Offline
Reply With Quote
Feb 16, 2003, 07:45 PM
 
Originally posted by Zim:
Which is fine as long as you are in a shell that got that alias...

Made me wonder tho... In a true brute force method, one could replace /bin/rm with a script of the alias... but I suspect Apple's delete really goes back and calls /bin/rm, so this would render Trash un-empty-able...

can anyone confirm?

Mike
Why would they incur the overhead of spawning a process to run /bin/rm when there is a perfectly good system call, unlink(2), for this?
     
Boochie
Mac Enthusiast
Join Date: Mar 2002
Status: Offline
Reply With Quote
Feb 16, 2003, 07:47 PM
 
Regarding your first point, it would be easy enough to perform some experiments using 'echo' to test potential problem scenarios.

As for resource forks, good point! I don't think the nominal mv command knows about them (cp doesn't, as I recall). There is also the 'ditto' command, which can handle them.

Of course, one could just do all this from the Finder...

Originally posted by Richard Edgar:
So are my shell escapes... will that combination ensure that all special characters get correctly passed down the line? Spaces are particularly important, since unexpected things could happen if they don't get escaped. What about if the command was a pattern match? Or worse, if one of the filenames contained wildcards? Remember "|", ";", "*", "!" and "\" are all perfectly legitimate characters to have in a filename - and great pain could result if they come up in a bad order. Such an order may be unlikely, but anything which is supposed to be robust and userfriendly must deal with all cases.

As a final thought, does mv know about resource forks?
     
Rainy Day
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status: Offline
Reply With Quote
Feb 16, 2003, 08:45 PM
 
Originally posted by Richard Edgar:
does mv know about resource forks?
No. See:

man MvMac
man CpMac

Off topic, but perhaps of interest:

man GetFileInfo
man SetFile


Originally posted by awaspaas:
Is there a way to override the standard rm command and instead have it move the item to .Trash like the Finder does?
A safer approach is to simply create a new command to do this, rather than fiddle with rm. Maybe create and alias for something like trash which calls MvMac?
     
Wevah
Senior User
Join Date: Nov 2001
Location: State of Denial
Status: Offline
Reply With Quote
Feb 17, 2003, 04:13 AM
 
Just what I was going to suggest.

Hooray!
[Wevah setPostCount:[Wevah postCount] + 1];
     
   
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
Top
Privacy Policy
All times are GMT -4. The time now is 04:28 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,