{"id":15,"date":"2007-02-05T16:20:27","date_gmt":"2007-02-05T15:20:27","guid":{"rendered":"http:\/\/schuerig.de\/michael\/blog\/?p=15"},"modified":"2021-11-24T09:20:10","modified_gmt":"2021-11-24T08:20:10","slug":"timestamp-servicemenu","status":"publish","type":"post","link":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/2007\/02\/05\/timestamp-servicemenu\/","title":{"rendered":"Timestamping files from commandline and Konqueror"},"content":{"rendered":"<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>\n<p><code>\/usr\/local\/bin\/timestamp<\/code><\/p>\n<p><code><\/p>\n<pre>\r\n#! \/bin\/sh\r\n\r\nfor oldname ; do\r\n  ts=`date +'%Y%m%d%H%M' --reference=\"$oldname\"`\r\n\r\n  newname=`echo $oldname | sed -nre \"s\/^(\\\\.?)([^\\\\.]+)(-[[:digit:]]{12})(\\\\..*)\\$\/\\\\1\\\\2-$ts\\\\4\/p\"`\r\n  if [ -z \"$newname\" ]; then\r\n    newname=`echo $oldname | sed -nre \"s\/^(\\\\.?)([^\\\\.]+)(\\\\..*)\\$\/\\\\1\\\\2-$ts\\\\3\/p\"`\r\n  fi\r\n  if [ -z \"$newname\" ]; then\r\n    newname=`echo $oldname | sed -nre \"s\/^(\\\\.?)([^\\\\.]+)(-[[:digit:]]{12})\\$\/\\\\1\\\\2-$ts\/p\"`\r\n  fi\r\n  if [ -z \"$newname\" ]; then\r\n    newname=`echo $oldname | sed -nre \"s\/^(\\\\.?)([^\\\\.]+)\\$\/\\\\1\\\\2-$ts\/p\"`\r\n  fi\r\n\r\n  if [ -f \"$newname\" ]; then\r\n    if [ \"$newname\" != \"$oldname\" ]; then\r\n      echo \"Can't rename $oldname to $newname: file already exists.\"\r\n    fi\r\n  else\r\n    echo mv \"$oldname\" \"$newname\"\r\n    mv \"$oldname\" \"$newname\"\r\n  fi\r\ndone\r\n<\/pre>\n<p><\/code><\/p>\n<p>As I&#8217;m using KDE as my desktop, I like to have the timestamping integrated. Fortunately, it&#8217;s easy.<\/p>\n<p><code>~\/.kde\/share\/apps\/konqueror\/servicemenus<\/code><\/p>\n<p><code><\/p>\n<pre>\r\nActions=timestamp\r\nServiceTypes=all\/all\r\n\r\n[Desktop Action timestamp]\r\nExec=\/usr\/local\/bin\/timestamp %u\r\nIcon=clock\r\nName=Timestamp\r\n<\/pre>\n<p><\/code><\/p>\n<p>See <a href=\"http:\/\/developer.kde.org\/documentation\/tutorials\/dot\/servicemenus.html\">Creating Konqueror Service Menus<\/a> for a general introduction.<\/p>\n<h4>Update, 2007-02-06<\/h4>\n<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>\n","protected":false},"excerpt":{"rendered":"<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. \/usr\/local\/bin\/timestamp #! \/bin\/sh for &hellip; <a href=\"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/2007\/02\/05\/timestamp-servicemenu\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,2,3],"tags":[],"class_list":["post-15","post","type-post","status-publish","format-standard","hentry","category-kde","category-linux","category-shell"],"_links":{"self":[{"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/posts\/15","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=15"}],"version-history":[{"count":1,"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/posts\/15\/revisions"}],"predecessor-version":[{"id":148,"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/posts\/15\/revisions\/148"}],"wp:attachment":[{"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.schuerig.de\/michael\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}