TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG:2572] I think this works!



On Sat, 5 Dec 1998, Ben Luey wrote:

> I think my perl script is now ready to replace rm. By copying the file(s)
> and then deleting them, I don't have to bother with all the syntax
> changing with using mv. Also perl deals with quotes used in filenames
> ("my long doc name.wpd" very well. If someone find any problems with the
> script (or reason not to rename rm and use this as rm and then cron a real
> delete of /home/delete) please e-mail me. 

It's a good script. I think by making some (perhaps unwarranted)
assumptions about your user's powers (i.e., it's a regular user who can
only mess with things in his home directory), you can do the following to
make the script more efficient:

1. $DELETEDIR = "$ENV{'HOME'}/.Trash" (I like for the trash can to be
hidden.)

2. Change the cp-ing to mv-ing (since there's no chance we could be
crossing paritions) and don't do the 'rm' step ('mv' precludes it). This
is much more efficient than copying and removing.

3. Yes, change the user's .aliases file (or whatever file you keep your
aliases in) to have 'rm' point to this script. You could also add an alias
('mtTrash' or some such) that does 'rm -rf ~/.Trash/*'.

This isn't the kind of thing I would ever do as root, for security reasons
among others, so the test to check if the user is root can go (unless you
want to make it exit safely if the user is root).

Here is my version of your script:

===
#!/usr/bin/perl

$DELETEDIR = "$ENV{'HOME'}/.Trash";

if (@ARGV[0] eq  "") {
	print "Syntax:\nrm [files and directories to delete]\n"
}
	else {
		foreach $test (@ARGV) {
        		$new .= '"';
			$new .= $test;
			$new .= '" ';
	};

if (!-e "$DELETEDIR") {
	`mkdir $DELETEDIR/$USER`
};

`mv -f $new $DELETEDIR`;
===

I haven't tested this, since I'm coming to you from my NeXTSTEP box, on
which I couldn't get 'perl' to compile. :) Try it out and see if you like
it. I'll try it myself later on.

_____________________________________________________________________________
Christopher Reid Palmer : reid@pconline.com : innerFire on IRC (EFNet)

"Luminous beings are we. Not this...crude matter."  -- Yoda