🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #16228

Re: Script para implementar una papelera en consola.

#16228
From: batsman
Date: Fri, 28 Apr 2000 00:00
79 lines
3037 bytes
-----BEGIN PGP SIGNED MESSAGE-----


  >> Qui�n: Santiago Romero
  >> Cu�ndo: Thu, 27 Apr 2000 13:25:21 +0200
  >> D�nde: es.comp.os.linux.programacion
  >> Por qu�: �Y yo qu� s�!

>
> Enas.
> He hecho el siguiente cutrescript para hacer borrado de ficheros
> con posibilidad de recuperacion (es decir, uso de una papelera en
> consola en lugar del clasico rm):
>
>
>#!/bin/sh
># Uso: delete fichero o directorio.
>
>if [ ! -d ~/trash ]; then \
>mkdir ~/trash; \
>fi
>
>mv $1 ~/trash
>
> 
> Funcionar funciona bien (perfectamente) excepto en el caso de que
> borre 2 ficheros con el mismo nombre (o ya exista uno con el nombre
> del borrado en trash). Es facil detectar si ya existe con test,
> pero... �como podria a�adirle a $1 algo asi como la fecha, o un
> 2,3,4,... para que no machaque el que ya existe� (en shell).

Aqu� tienes:

:r ~/bin/borra
#!/bin/sh

if [ ! -d ~/.trash ]; then 
	mkdir ~/.trash;
fi

#echo "Borrando archivos:"
#echo $*

dir=~/.trash

for n in $*;  do
#	echo "Borrando archivo $n"
	if [ -e ~/.trash/$n ]; then
		mv $n "$dir/$n.`date|tr ' ' '-' `";
	else
		mv $n ~/.trash/$n;
	fi
done

No he tenido en cuenta los malos rollos de seguridad, etc...
NOTA: ahora puedes hacer [~]$ borra *.o por ejemplo

- -- 
              _           _                             
             | |__   __ _| |_ ___ _ __ ___   __ _ _ __  
             | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ 
             | |_) | (_| | |_\__ \ | | | | | (_| | | | |
             |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|

             Real email: batsman dot geo at yahoo dot com

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: noconv
Comment: Public key via email: send mail with Subject: [PGPKEY]

iQEVAwUBOQnYJ70Y27yr0iefAQG0Ygf9HIfBO0eGfwufHVZDBZpzMLZWxAPM68HL
AFfeg7TcWIxMD+uuycMz7pGpiXQS3XvsvJpqwAfrlGQhb0dwww7FsG1/YpxjAPx4
FCnuZikJFe5m+/+a6+KQCcSeMyS9yVtquKrUwH2hk1510AwUDPlaTd7/+nSS9drP
ASqs8WfH/hqYnVi9izl1rQuX8utxMZkCrGleomq1QJjf5YUbLkn+7h8jxf9tW+hP
/oPIa0lZ+aoMtTmhlnk7ryqI0TwxHXf+1mMjJbZSgPQBIITA8xrCbn6wBhC1tJ7l
HtDbAEQg2onPKahEr+QiYvyREf7kkAkZMZwgHJdE6y/FP2hXCMPYTg==
=rAvD
-----END PGP SIGNATURE-----
Technical Details
Message-ID: <c7lce8.j11.ln@simpsons4ever>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <slrn8gg8t1.13r.nop@compiler.linux.es>

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: f86c8,342b0ba2d125e766
X-Google-Attributes: gidf86c8,public
From: batsman@simpsons.for.ever (batsman)
Subject: Re: Script para implementar una papelera en consola.
Date: 2000/04/28
Message-ID: <c7lce8.j11.ln@simpsons4ever>
X-Deja-AN: 616844522
Content-Transfer-Encoding: 8bit
References: <slrn8gg8t1.13r.nop@compiler.linux.es>
Content-Type: text/plain; charset=iso-8859-1
X-Complaints-To: abuse@news.wanadoo.es
X-Trace: m2newsread.uni2.es 956940356 62.36.7.118 (Fri, 28 Apr 2000 18:45:56 MET DST)
Organization: Wanadoo Usenet News - Visita http://www.wanadoo.es/
Mime-Version: 1.0
User-Agent: slrn/0.9.5.3 (UNIX)
Reply-To: see_signature-mira_firma
NNTP-Posting-Date: Fri, 28 Apr 2000 18:45:56 MET DST
Newsgroups: es.comp.os.linux.programacion