Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
mass replace timestamp with that of a similar file?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
Jiokah
Tux's lil' helper
Tux's lil' helper


Joined: 28 Nov 2006
Posts: 90
Location: Toronto

PostPosted: Thu Jan 17, 2008 12:19 am    Post subject: mass replace timestamp with that of a similar file? Reply with quote

Hi guys,

Got a question!

I have about a hundred files that I've run a few batch commands on with Photoshop (In windows, but the files are stored on my network server, which runs Gentoo). The resulting files now have JPG extensions, with the old files having BMP extensions, with the filename itself remaining the same.

Here's what I want to do:

Transfer the timestamp of all BMP files to their counterpart JPG files.

Would any one know how? Even just a shot in the right direction will help me. I run a production web server serving many hand-built web apps built by me, so I'm not TOO far out of the woods on these things, but I'm still quite inept.

Thanks a lot!

-Matthew
Back to top
View user's profile Send private message
linear
Apprentice
Apprentice


Joined: 12 Aug 2004
Posts: 222

PostPosted: Thu Jan 17, 2008 12:29 am    Post subject: Reply with quote

The particular utility you need for this is 'touch'.

HTH.
Back to top
View user's profile Send private message
MotivatedTea
Apprentice
Apprentice


Joined: 06 Nov 2006
Posts: 269
Location: Toronto, Canada

PostPosted: Thu Jan 17, 2008 12:33 am    Post subject: Reply with quote

In particular, you want the "-r" parameter. So a little for loop at a bash prompt would work:
Code:
for f in *.BMP; do touch -r $f ${f/BMP/JPG}; done

This would set the timestamp of all JPG files to match those of the BMP files with the same name. (Extensions are case sensitive, so you may need to use "*.bmp" and "${f/bmp/jpg}".
Back to top
View user's profile Send private message
Jiokah
Tux's lil' helper
Tux's lil' helper


Joined: 28 Nov 2006
Posts: 90
Location: Toronto

PostPosted: Thu Jan 17, 2008 8:56 pm    Post subject: Reply with quote

Ah it worked like a charm!

One last question, the syntax used here, what's it called? I'm a pro at PHP and if I could just figure out the syntax for linux I wouldn't need to learn a whole lot to get into some useful programming.

Thanks a ton!
Back to top
View user's profile Send private message
timeBandit
Bodhisattva
Bodhisattva


Joined: 31 Dec 2004
Posts: 2719
Location: here, there or in transit

PostPosted: Thu Jan 17, 2008 9:06 pm    Post subject: Reply with quote

See man bash for all the gory details. The trick above is covered under Parameter Expansion.
_________________
Plants are pithy, brooks tend to babble--I'm content to lie between them.
Super-short f.g.o checklist: Search first, strip comments, mark solved, help others.
Back to top
View user's profile Send private message
Jiokah
Tux's lil' helper
Tux's lil' helper


Joined: 28 Nov 2006
Posts: 90
Location: Toronto

PostPosted: Thu Jan 17, 2008 9:32 pm    Post subject: Reply with quote

Hey thanks

By the way, your avatar rocks. Commander Keen was the best hands down.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum