|
|
rm = mv to .Trash?
|
|
|
|
Mac Elite
Join Date: Apr 2001
Location: Minneapolis, MN
Status:
Offline
|
|
Is there a way to override the standard rm command and instead have it move the item to .Trash like the Finder does?
|
|
|
|
|
|
|
|
|
Senior User
Join Date: Jun 2002
Location: UK
Status:
Offline
|
|
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...
|
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Mar 2002
Status:
Offline
|
|
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!
|
|
|
|
|
|
|
|
|
Senior User
Join Date: Apr 2001
Location: Cary, NC
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Mar 2002
Status:
Offline
|
|
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
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: May 2001
Status:
Offline
|
|
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 )
-
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Sep 2002
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Mar 2002
Status:
Offline
|
|
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.
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Sep 2002
Status:
Offline
|
|
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?
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Nov 2000
Status:
Offline
|
|
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?
|
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Mar 2002
Status:
Offline
|
|
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?
|
|
|
|
|
|
|
|
|
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status:
Offline
|
|
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?
|
|
|
|
|
|
|
|
|
Senior User
Join Date: Nov 2001
Location: State of Denial
Status:
Offline
|
|
Just what I was going to suggest.
Hooray!
|
[Wevah setPostCount:[Wevah postCount] + 1];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|