<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Nos pasa algo lo mismo &#187; script</title>
	<atom:link href="http://www.tatai.es/tag/script/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tatai.es</link>
	<description>...está claro...</description>
	<lastBuildDate>Thu, 09 Jun 2011 18:12:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Trabajar con ficheros a partir de una fecha y hora</title>
		<link>http://www.tatai.es/2010/01/03/trabajar-con-ficheros-a-partir-de-una-fecha-y-hora/</link>
		<comments>http://www.tatai.es/2010/01/03/trabajar-con-ficheros-a-partir-de-una-fecha-y-hora/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 22:14:07 +0000</pubDate>
		<dc:creator>tatai</dc:creator>
				<category><![CDATA[trucos]]></category>
		<category><![CDATA[consola]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[touch]]></category>

		<guid isPermaLink="false">http://www.tatai.es/?p=654</guid>
		<description><![CDATA[Al hilo del post de ayer sobre date, hace poco tuve que realizar un sencillo script que borrase todos aquellos ficheros más viejos que una determinada fecha (en particular, ayer a las 6.30h). Seguramente habrás pensado que la mejor opción es un find con -atime (o -mtime o -amin o -cmin, etc) y posteriormente con [...]]]></description>
			<content:encoded><![CDATA[<p>Al hilo del <a href="http://www.tatai.es/2010/01/02/ir-a-una-fecha-mediante-texto/">post de ayer sobre date</a>, hace poco tuve que realizar un sencillo script que borrase todos aquellos ficheros más viejos que una determinada fecha (en particular, ayer a las 6.30h).</p>
<p>Seguramente habrás pensado que la mejor opción es un find con -atime (o -mtime o -amin o -cmin, etc) y posteriormente con un -exec. Bien, es una buena idea aunque yo quería que fuese a partir de un determinado momento exactamente, sin calcular. Para esto, también usé find, pero me apoyé en date y en touch y quedó algo así:</p>
<p><code>#!/bin/bash<br />
# La fecha y hora de ayer a las 6.30h<br />
FECHA=$( date +-d "06:30 yesterday" +"%Y/%m/%d %H:%M:%S" )<br />
# Fichero temporal<br />
POINT=$( tempfile -p "point" )<br />
# Cambiamos la fecha del fichero temporal<br />
touch -d "${FECHA}" ${POINT}<br />
# Buscamos ficheros más viejos que ${POINT} y los borramos<br />
find /path/al/destino -not -newer ${POINT} -exec rm {} \;<br />
# Borramos basura<br />
rm ${POINT}</code></p>
<p>Es posible que sea algo más lioso, pero sin tener que calcular nada (por ejemplo la diferencia de tiempo entre cuando ejecutemos el fichero y nuestra hora objetivo), hacemos el trabajo rápidamente. Y también podemos cambiar la hora de una forma muy cómoda.</p>
<h2>Más info</h2>
<p>Este &#8220;más info&#8221; va a ser un claro RTFM <img src='http://www.tatai.es/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<ul>
<li>man find</li>
<li>man date</li>
<li>man touch</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.tatai.es/2010/01/03/trabajar-con-ficheros-a-partir-de-una-fecha-y-hora/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

