In: , , ,
On: 2004 / 12 / 01 Viewed: 41225 times

One thing really silly is the way digital cameras name their files : dsc00001.jpg or something similar, which is quite annoying when you try to sort old pictures. So I made a small bash script that renames every picture with a more useful filename : 041131-001.jpg for example. To do so, I'm using a Perl script I've made, datemodif, which outputs a modification date in various formats, but I wanted to do a more portable script, using only Bash and default GNU utils, but not Perl.

After some testing, here is the function I've added to my .bash_profile :

CODE:
  1. function getmodif {
  2.    stat -c "%y" $1 | cut -d" " -f1 | sed -e 's/..//' -e 's/-//g'
  3. }

Sample output :

CODE:
  1. [ozh@SARL ~/htdocs/ozh]$ ls -l index.php
  2. -rw-r--r--    1 sarl     515         20728 nov 30 23:13 index.php
  3. [sarl@SARL ~/htdocs/ozh]$ getmodif index.php
  4. 041130

Related posts

Metastuff

This entry "File Modification Date in Bash" was posted on 01/12/2004 at 11:29 pm and is tagged with , , ,
Watch this discussion : Comments RSS 2.0. You can trackback this post from your own site

One Reply

  1. 1
    Marcelo Magalhaes Brazil »
    wrote, on 29/Jan/08 at 8:23 pm # :

    Silly but very useful. Thanks a lot.

Leave a Reply

Comment Guidelines or Die

  • HTML: You can use these tags: <a href=""> <em> <i> <b> <strong> <blockquote>
  • Posting code: Post raw code (no <> &lt; etc) within appropriate tags : [php][/php], [css][/css], [html][/html], [js][/js], [sql][/sql], [xml][/xml], or generic [code][code]
  • Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar.
  • Spam: Various spam plugins on patrol. I'll put pins in a Voodoo doll if you spam me.
  • I will mark as Spam test comments, all comments with SEO names (ie "My Cool Online Shop" instead of "Joe") or containing forum-like signatures.

Read more ?

Close
E-mail It