In: , , ,
On: 2004 / 12 / 01
Shorter URL for this post:

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 :

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

Sample output :

  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

Shorter URL

Want to share or tweet this post? Please use this short URL:


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.

One Reply

  1. Marcelo Magalhaes says:

    Silly but very useful. Thanks a lot.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar and sign for a free account
Spam: Various spam plugins may be activated. I'll put pins in a Voodoo doll if you spam me.

Read more ?