|
Home > Archive > Unix questions > February 2006 > Changing just the year of a file?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Changing just the year of a file?
|
|
|
| Hi all-
I have a bunch of files (jpegs from my digital camera) that have the
correct date and time, but the year is off by one (it says 2005). There
are about 900 of these files, and I'm trying to write a script that
will use the touch utility to change them to the correct year.
The problem is that I can't seem to get it to change *just* the year. I
figure I have to get the file attributes (date and time) and then feed
that back to touch adjusting the year, but haven't been able to get
this info using a script. In all honesty, I'm not sure which command to
use.
Might anyone have an idea how best to go about this?
Thanks,
Ron
| |
| Barry Margolin 2006-02-19, 8:29 am |
| In article <1140315885.918882.28800@g43g2000cwa.googlegroups.com>,
"Ron" <tachoknight@gmail.com> wrote:
> Hi all-
>
> I have a bunch of files (jpegs from my digital camera) that have the
> correct date and time, but the year is off by one (it says 2005). There
> are about 900 of these files, and I'm trying to write a script that
> will use the touch utility to change them to the correct year.
>
> The problem is that I can't seem to get it to change *just* the year. I
> figure I have to get the file attributes (date and time) and then feed
> that back to touch adjusting the year, but haven't been able to get
> this info using a script. In all honesty, I'm not sure which command to
> use.
>
> Might anyone have an idea how best to go about this?
If you have GNU ls, you can use its --full-time option to get the full
date and time. It should then be relatively easy to extract each date
component with awk, add 1 to the year, and reformat this as the argument
to touch.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
| |
| Chris F.A. Johnson 2006-02-19, 8:29 am |
| On 2006-02-19, Ron wrote:
> Hi all-
>
> I have a bunch of files (jpegs from my digital camera) that have the
> correct date and time, but the year is off by one (it says 2005). There
> are about 900 of these files, and I'm trying to write a script that
> will use the touch utility to change them to the correct year.
>
> The problem is that I can't seem to get it to change *just* the year. I
> figure I have to get the file attributes (date and time) and then feed
> that back to touch adjusting the year, but haven't been able to get
> this info using a script. In all honesty, I'm not sure which command to
> use.
>
> Might anyone have an idea how best to go about this?
If you have GNU date:
for file in "$@"
do
filedate=$( date -r "$file" +"%Y%m%d%H%M.%S" )
newyear=$(( ${filedate%${filedate#????}} + 1 ))
touch $file -t $newyear${filedate#????}
done
If you don't have GNU date, then you need to extract the
timestamp of the file by some other means (e.g., 'ls -l' or
'stat').
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
| |
| Stephane CHAZELAS 2006-02-19, 5:50 pm |
| 2006-02-18, 18:24(-08), Ron:
> Hi all-
>
> I have a bunch of files (jpegs from my digital camera) that have the
> correct date and time, but the year is off by one (it says 2005). There
> are about 900 of these files, and I'm trying to write a script that
> will use the touch utility to change them to the correct year.
>
> The problem is that I can't seem to get it to change *just* the year. I
> figure I have to get the file attributes (date and time) and then feed
> that back to touch adjusting the year, but haven't been able to get
> this info using a script. In all honesty, I'm not sure which command to
> use.
[...]
JPEGs from digital camera have an EXIF header that contain a lot
of informations such as the time of the shot, the focal length,
aperture, exposure time and for some the orientation, GPS
position...
It would make more sense if you changed that embeded data rather
than the file modification time, and that you then make the
modification time the same as the embeded time.
There are many existing tools to do that.
jhead is the one with useful timestamping options:
jhead -da2006:01:01-2005:01:01 ./*.jpg
will fix the time in your image.
jhead -ft ./*.jpg
will make the modification time reflect the time of shooting.
See http://www.sentex.net/~mwandel/jhead/
--
Stéphane
| |
| Timo Salmi 2006-02-20, 7:48 am |
| Ron <tachoknight@gmail.com> wrote:
> I have a bunch of files (jpegs from my digital camera) that have the
> correct date and time, but the year is off by one (it says 2005). There
> are about 900 of these files, and I'm trying to write a script that
> will use the touch utility to change them to the correct year.
I know that your question is for UNIX. That already has been
aswered. However, should you be interested in the same task with a
Windows (XP) script take a look at news:alt.msdos.batch.nt and my
posting "How do I advance the dates of my certain JPG files by one
year?". The crossover suggestion here is because digiphotos are so
often stored on one's PC.
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; university of Vaasa
mailto:ts@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html
|
|
|
|
|