[robg adds: Another variation on this script was detailed in this hint.]
|
|
|
Out of the many cool hacks on O'Reilly's hacks site is one by Rael Dornfest which replaces the rm command with a new version with Finder-like behavior. The result: if you rm a file in the Terminal, it shows up in the Trash can, waiting for that final confirmation before you manually delete it for good.
[robg adds: Another variation on this script was detailed in this hint.]
•
[7,338 views]
Hint Options
Why not MvMac?
I downloaded the rmm script, and it works very well. One question, though: why does it use CpMac to copy the file to ~/.Trash and then rm to remove it? Could it save a step by just using MvMac to move the file (resource fork and all) to ~/.Trash? Am I missing something?
Why not MvMac?
Because MvMac apparently doesn't work accross different file
Why not MvMac?
And why not using MvMac when both source and destination volumes are the same and CpMac otherwhise? This way the speed will be improved in many cases.
Make 'rm' behave like the Finder trash
For people who are used to the unix rm command, this script
CpMac a bad choice
I don't know why Gary Kerbaugh decided to use CpMac in his rmm script (the script in question). CpMac is only included in the Developer Tools, a 300+MB download and optional install, so it will not be on every Mac.
% which CpMac /Developer/Tools/CpMacAdditionally, CpMac does not preserve permissions: Utility Preserves Permissions? Preserves Resource Forks & Creator/Type? cp yes no CpMac no yes ditto yes yes rsync yes no(Chart from: http://www.macdevcenter.com/pub/a/mac/2002/07/02/terminal_5.html) This may or may not be a problem, especially since the items are destined for deletion anyway. My pedantic nature, however, dictates preserving the file intact until it is actually removed from the filesystem. Therefore, I suggest replacing CpMac in Gary's script with ditto (thus recreating the file exactly, with both permissions and resource fork information intact). Additionally, ditto is part of the default OS X distribution, so it can be counted upon to be on any system upon which this script is deployed. % which ditto /usr/bin/ditto
CpMac a bad choice
Are you sure that ditto is not installed by the developer tools? I don't know,
but being in /usr/bin doesn't necessarily mean it's included in a default install.
For example, gcc was installed by the Developer tools (I'm almost certain):
CpMac a bad choice
Additionally, CpMac does not preserve permissions It does if you use the '-p' flag:
-p flag
The -p flag on CpMac does not mean the same thing as the -p flag on cp. Note the fine difference (from man CpMac):
CpMac - copy files preserving metadata and forks -p Causes CpMac to preserve in the copy as many of the modification time, access time, file flags, file mode, user ID, and group ID as allowed by permissions.
Make 'rm' behave like the Finder trash
Reading this post got me thinking about the proper 'mac' way to do this, so I made an ugly ugly ugly tcsh alias that does something similar.
Make 'rm' behave like the Finder trash
Re: converting unix pathnames to regular ones, I think something like
Using MvMac when possible to increase speed
This script is really great except for one reason: it always uses CpMac even when what we want to remove is in the same volume in which ~/.Trash is. In that circunstance, MvMac will be much faster.
I propose an easy solution: just try MvMac and if it fails (because the volumes are different) try CpMac + rm. You have to replace de "move_file()" function in the script with this code:
move_file ()
{
if [ -n "$verbopt" ]; then
echo "Moving $1 to trash."
chflags -R nouchg "$1"
/Developer/Tools/MvMac "$1" "$dest" || (/Developer/Tools/CpMac "$1" "$dest" && /bin/rm "$1")
elif [ -n "$forceopt" ]; then
chflags -R nouchg "$1" > /dev/null 2>&1
/Developer/Tools/MvMac "$1" "$dest" > /dev/null 2>&1 || (/Developer/Tools/CpMac "$1" "$dest" > /dev/null 2>&1 && /bin/rm "$1" > /dev/null 2>&1)
else
chflags -R nouchg "$1"
/Developer/Tools/MvMac "$1" "$dest" || (/Developer/Tools/CpMac "$1" "$dest" && /bin/rm "$1")
fi
}
(The lines starting with /Developer... are quite long but must be written in one line)
Luis
|
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.17 seconds |
|