Find the answer to your Linux question:
Results 1 to 6 of 6
Hi all, I want to write a script to rename all files in a directory to include the 'date modified', i.e. 'File.XXX' to 'SomeDate_File.XXX' I'm just going to be using ...
  1. #1
    Just Joined!
    Join Date
    May 2009
    Posts
    1

    multiple file rename

    Hi all,

    I want to write a script to rename all files in a directory to include the 'date modified', i.e. 'File.XXX' to 'SomeDate_File.XXX'

    I'm just going to be using the modified date string as a differentiator for identically named files (my digital video camera writes files to the onboard HD as MOV00A, MOV00B, and uses the same naming convention each time the HD is formatted). Not particularly concerned about what the date string will look like, but it would be nice if Nautilus could still sort the files by name in a manner that reflects the date - if that makes sense? :)

    Is there an easy way to do this?

    Much obliged,

    Dave

  2. #2
    Just Joined!
    Join Date
    Dec 2006
    Posts
    85
    hmm...renaming all files to something is reletively simple, you can do it with bash:
    for i in *filename-matching-string*; do cp $i (new name); done
    now getting the modified date...hmm..im not really sure...one thing you can do is just affix them all with todays date (since they will be modified today and every time this is ran) but to match their existing modified date...im not sure.
    here would be the code for that
    Code:
    #!/bin/bash
    for i in *; do mv $i $i.` date --rfc-3339=date`;done
    im sure someone better with bash will provide a better solution, but thats the best i can do...

  3. #3
    Linux User
    Join Date
    May 2008
    Location
    NYC, moved from KS & MO
    Posts
    251
    To get modified time of a file:
    stat -c %y file

  4. #4
    Linux Newbie
    Join Date
    Nov 2007
    Location
    Planet Earth
    Posts
    152
    To get your files in format 2009_05_29_MOV00A, acording to the modification date:
    Code:
    #! /bin/bash
    for file in MOV*
    do
       modifdate=`stat -c %y $file`
       formatdate=`date -d "$modifdate" +%Y_%m_%d_`
       mv $file $formatdate$file
    done
    EOF

  5. #5
    Just Joined!
    Join Date
    Dec 2006
    Posts
    85
    see this is why open source is amazing

  6. #6
    Linux Newbie raghaven.kumar's Avatar
    Join Date
    Mar 2008
    Location
    Bangalore, India
    Posts
    209

    Cool

    Quote Originally Posted by the_ultimate_samurai View Post
    see this is why open source is amazing
    Yo! man!
    Thats why its cool

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...