<?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>Michael Schuerig &#187; KDE</title>
	<atom:link href="http://www.schuerig.de/michael/blog/index.php/category/kde/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.schuerig.de/michael/blog</link>
	<description>Sentenced to making sense</description>
	<lastBuildDate>Tue, 06 Sep 2011 07:21:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Timestamping files from commandline and Konqueror</title>
		<link>http://www.schuerig.de/michael/blog/index.php/2007/02/05/timestamp-servicemenu/</link>
		<comments>http://www.schuerig.de/michael/blog/index.php/2007/02/05/timestamp-servicemenu/#comments</comments>
		<pubDate>Mon, 05 Feb 2007 15:20:27 +0000</pubDate>
		<dc:creator>michael</dc:creator>
				<category><![CDATA[KDE]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://schuerig.de/michael/blog/?p=15</guid>
		<description><![CDATA[In order to keep multiple versions of a file, I sometimes add a timestamp to the filename. Doing this by hand is tedious and error-prone, but this chore can be automated by a small shell script. /usr/local/bin/timestamp #! /bin/sh for oldname ; do ts=`date +'%Y%m%d%H%M' --reference="$oldname"` newname=`echo $oldname &#124; sed -nre "s/^(\\.?)([^\\.]+)(-[[:digit:]]{12})(\\..*)\$/\\1\\2-$ts\\4/p"` if [ -z [...]]]></description>
			<content:encoded><![CDATA[<p>In order to keep multiple versions of a file, I sometimes add a timestamp to the filename. Doing this by hand is tedious and error-prone, but this chore can be automated by a small shell script.</p>
<p><code>/usr/local/bin/timestamp</code></p>
<p><code>
<pre>
#! /bin/sh

for oldname ; do
  ts=`date +'%Y%m%d%H%M' --reference="$oldname"`

  newname=`echo $oldname | sed -nre "s/^(\\.?)([^\\.]+)(-[[:digit:]]{12})(\\..*)\$/\\1\\2-$ts\\4/p"`
  if [ -z "$newname" ]; then
    newname=`echo $oldname | sed -nre "s/^(\\.?)([^\\.]+)(\\..*)\$/\\1\\2-$ts\\3/p"`
  fi
  if [ -z "$newname" ]; then
    newname=`echo $oldname | sed -nre "s/^(\\.?)([^\\.]+)(-[[:digit:]]{12})\$/\\1\\2-$ts/p"`
  fi
  if [ -z "$newname" ]; then
    newname=`echo $oldname | sed -nre "s/^(\\.?)([^\\.]+)\$/\\1\\2-$ts/p"`
  fi

  if [ -f "$newname" ]; then
    if [ "$newname" != "$oldname" ]; then
      echo "Can't rename $oldname to $newname: file already exists."
    fi
  else
    echo mv "$oldname" "$newname"
    mv "$oldname" "$newname"
  fi
done
</pre>
<p></code></p>
<p>As I&#8217;m using KDE as my desktop, I like to have the timestamping integrated. Fortunately, it&#8217;s easy.</p>
<p><code>~/.kde/share/apps/konqueror/servicemenus</code></p>
<p><code>
<pre>
Actions=timestamp
ServiceTypes=all/all

[Desktop Action timestamp]
Exec=/usr/local/bin/timestamp %u
Icon=clock
Name=Timestamp
</pre>
<p></code></p>
<p>See <a href="http://developer.kde.org/documentation/tutorials/dot/servicemenus.html">Creating Konqueror Service Menus</a> for a general introduction.</p>
<h4>Update, 2007-02-06</h4>
<p>I&#8217;ve updated the script to insert the timestamp before all the first extension and to also work with filename starting with a &#8216;<code>.</code>&#8216;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.schuerig.de/michael/blog/index.php/2007/02/05/timestamp-servicemenu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

