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 ...
- 05-24-2009 #1Just 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
- 05-24-2009 #2Just 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
im sure someone better with bash will provide a better solution, but thats the best i can do...Code:#!/bin/bash for i in *; do mv $i $i.` date --rfc-3339=date`;done
- 05-27-2009 #3Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
To get modified time of a file:
stat -c %y file
- 05-27-2009 #4Linux 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
- 05-27-2009 #5Just Joined!
- Join Date
- Dec 2006
- Posts
- 85
see this is why open source is amazing
- 05-27-2009 #6


Reply With Quote
