Shell Easily reverting file modification times to creation times.

Today I moved around five years' worth of photos with pcmanfm on 13.1-RELEASE.

I was surprised to discover that pcmanfm had changed the modification times. For instance, a file modified in 2018 showed up with as having been modified today, post-move.

Thankfully creation times were still visible with ls -lU.

I did this to revert modification times back to creation times, and it worked.

But is there an easier way?

Code:
zsh% for X Y in $(ls -lUD %Y%m%d%H%M.%S | awk '{print $6 " " $7}'); do
>     touch -t $X $Y
> done

Thank you very much.
 
No, not really.

All "touch -t" does is set the time stamp. You could have been a little more efficient by using a "program" to do so. That would have saved time, namely the time to start the "touch" executable every time. So one way to do it would be a small perl or python program; in those programming languages, it is easy to write a program (it's just like a script, and you can even do it interactively), and they can do the equivalent of what "touch -t" does (namely the utimes system call) internally. That would also have taken care of running the "ls" and "awk", but those are only run once, so from an efficiency standpoint it wouldn't have been faster.
 
Back
Top