Changing date format in filenames in Linux [Solved]

I think I may have found it Keith…

The filenames in my ‘real’ folder are separated by underscores, not hyphens. My mistake.

EDIT: I have to go to bed now Keith - early start tomorrow. I’ll come back to this tomorrow.

No problem, Mike - I’ve done that before now!

You can modify the script as follows:

[ol]

  • open the script in your text editor
  • look for the phrase cut -d “-” (there are five of them)
  • change the hyphen to underscore and then
  • look for new_file=$year"-“$month”-“$day”."$suffix and change the two hyphens to underscore if you want underscore - or leave it if hyphens are OK in the new names.
    [/ol]

Bob’s your uncle.

I guess you’ll have to delete all the files, copy your backup files to that directory then rerun the code.
Good luck.

Keith

Keith,

I’ve done the above and your script works perfectly now. It will be a great help to me and allow me to sort files sensibly by date in future.

I’ve also learned a bit about scripting in the process, which is nice. It felt good to be using the keyboard a bit more again. I remember being a bit disdainful of the mouse when Windows 3.1 was released but we’ve all got used to pointing and clicking since then.

Again, thanks for your patience and your help

Mike

My pleasure, Mike. I’m pleased it all worked eventually.
I do hope you do a bit more scripting, although it does become addictive!

Keith