Unix Shell - change rm command

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > October 2005 > change rm command





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author change rm command
Diane

2005-10-30, 5:51 pm

How can I change the rm command to send all the deleted files to a
trash directory?

base60

2005-10-30, 5:51 pm

Diane wrote:
> How can I change the rm command to send all the deleted files to a
> trash directory?
>



"man alias"
Janis Papanagnou

2005-10-30, 5:51 pm

Diane wrote:
> How can I change the rm command to send all the deleted files to a
> trash directory?
>


Is this homework?

For an example see my reply to Telis' posting.
Then define an alias called rm to refer to that program.

Janis
Diane

2005-10-30, 5:51 pm

No, actually I am trying to create a trash directory to ensure that I
won't delete things I don't want since I'm a beginner in UNIX. I had a
look in your shell script you sent to Telis, but to tell the truth it
confussed me a bit. Could you please give me a simpler example on how
to create such a directory? Thanks!

Janis Papanagnou wrote:
> Diane wrote:
>
> Is this homework?
>
> For an example see my reply to Telis' posting.
> Then define an alias called rm to refer to that program.
>
> Janis


Janis Papanagnou

2005-10-30, 5:51 pm

Diane wrote:
> No, actually I am trying to create a trash directory to ensure that I
> won't delete things I don't want since I'm a beginner in UNIX.


....and new to Usenet? Please *don't* top-post!


To create a trash directory...

mkdir "$HOME/.trash"

To define a new remove function...

rmx()
{
/bin/mv "$@" "$HOME/.trash"
}

To overlay the rm command...

alias rm=rmx

To use the predefined remove command...

\rm yourfiles


Janis


> I had a
> look in your shell script you sent to Telis, but to tell the truth it
> confussed me a bit. Could you please give me a simpler example on how
> to create such a directory? Thanks!
>
> Janis Papanagnou wrote:
>
>
>

Janis Papanagnou

2005-10-30, 5:51 pm

Janis Papanagnou wrote:
> Diane wrote:
>
>
> To create a trash directory...
>
> mkdir "$HOME/.trash"
>
> To define a new remove function...
>
> rmx()
> {
> /bin/mv "$@" "$HOME/.trash"
> }
>
> To overlay the rm command...
>
> alias rm=rmx


My wording might mislead you.

To put your files into the .trash directory...

rm yourfiles

> To use the predefined remove command...

"predefined" here means the original Unix rm command.
> \rm yourfiles

or alternatively...
/bin/rm yourfiles


Janis
Diane

2005-10-30, 5:51 pm

I tried the script your suggested but unfortunately it didn't work. I
think that the rmx function for some reason does not work. Is there any
other way to save copies of my deleted files in the trash directory? I
also tried the following:

if (-e $file) then
cp -rp $file ~/trash
rm -rf $file
endif

I didn't receive any errors with that, but when I opened the trash
directory it was empty even if I had deleted some files.


Janis Papanagnou wrote:
> Janis Papanagnou wrote:
>
> My wording might mislead you.
>
> To put your files into the .trash directory...
>
> rm yourfiles
>
> "predefined" here means the original Unix rm command.
> or alternatively...
> /bin/rm yourfiles
>
>
> Janis


Bill Marcum

2005-10-30, 8:48 pm

On 30 Oct 2005 14:35:16 -0800, Diane
<froufrou_00@hotmail.com> wrote:
> I tried the script your suggested but unfortunately it didn't work. I
> think that the rmx function for some reason does not work. Is there any
> other way to save copies of my deleted files in the trash directory? I
> also tried the following:
>
> if (-e $file) then
> cp -rp $file ~/trash
> rm -rf $file
> endif
>

Which shell are you using? The commands above look like csh, while
everyone has been giving you scripts for a Bourne-type shell. If you
aren't sure what you have, type
echo $SHELL


--
He who knows, does not speak. He who speaks, does not know.
-- Lao Tsu
Diane

2005-10-31, 7:56 am

I'm sorry I didn't tell you earlier. I use csh.


Bill Marcum wrote:
> On 30 Oct 2005 14:35:16 -0800, Diane
> <froufrou_00@hotmail.com> wrote:
> Which shell are you using? The commands above look like csh, while
> everyone has been giving you scripts for a Bourne-type shell. If you
> aren't sure what you have, type
> echo $SHELL
>
>
> --
> He who knows, does not speak. He who speaks, does not know.
> -- Lao Tsu


Michael Heiming

2005-10-31, 7:56 am

In comp.unix.shell Diane <froufrou_00@hotmail.com>:
> How can I change the rm command to send all the deleted files to a
> trash directory?


Is there a special reason for posting the same question again,
with another account and another subject "create recycle bin"?

--
Michael Heiming (X-PGP-Sig > GPG-Key ID: EDD27B94)
mail: echo zvpunry@urvzvat.qr | PERL -pe 'y/a-z/n-za-m/'
#bofh excuse 252: Our ISP is having
{switching,routing,SMDS,frame relay} problems
Ed Morton

2005-10-31, 7:56 am

Diane wrote:
> I'm sorry I didn't tell you earlier. I use csh.


Diane - please read these:

http://en.wikipedia.org/wiki/Top-posting
http://home.comcast.net/~j.p.h/cus-faq-2.html#17

so you'll understand why you've been asked to stop top-posting and why
csh is a poor choice for scripting.

Regards,

Ed.
Enrique Perez-Terron

2005-10-31, 5:58 pm

On Mon, 31 Oct 2005 11:47:33 +0100, Diane <froufrou_00@hotmail.com> wrote:

> I'm sorry I didn't tell you earlier. I use csh.


Try this:


mkdir ~/trash
alias rm mv \!\* \~/trash

echo Hello World > delete-me
rm delete-me
ls delete-me
ls ~/trash

-Enrique
Keith Thompson

2005-10-31, 5:58 pm

Ed Morton <morton@lsupcaemnt.com> writes:
> Diane wrote:
>
> Diane - please read these:
>
> http://en.wikipedia.org/wiki/Top-posting
> http://home.comcast.net/~j.p.h/cus-faq-2.html#17
>
> so you'll understand why you've been asked to stop top-posting and why
> csh is a poor choice for scripting.


csh is a poor choice for scripting, but many people prefer it for
interactive use -- and if you're using it interactively, you'll have
to do *some* scripting to set up aliases and so forth.

If you're just starting out, it's probably a good idea to use bash or
some other sh-based shell both interactively and for scripting.

If you're a csh user, tcsh adds some very nice features for
interactive use (though it's not significantly better for scripting).

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com