Replace ":" from multiple files names (even recursively in directories)
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Replace ":" from multiple files names (even recursively in directories)
Hi
I need to replace ":" from multiple files names, since I am going to copy those files from a linux partition, which admit the ":" to a FAT32 partition, which does not. Example:
original name: eg06_ana_21-05-06_09:21:03.JPG
wished name: eg06_ana_21-05-06_09-21-03.JPG
I have googled a lot but I have not been able to adapt the examples given by people to my aim.
It seems that rename command is what I should use, but I have no idea to build the correct pearl expression.
$ ls
eg06_ana_21-05-06_09:21:03.JPG
$ for i in $( find -name \*JPG ); do echo mv $i $(echo $i|tr ':' '-'); done
mv ./eg06_ana_21-05-06_09:21:03.JPG ./eg06_ana_21-05-06_09-21-03.JPG
If this does what you expect, just remove the BOLD echo and run it.
[edit]
But while you're at it, why not convert the date to an iso
date so your files sort chronologically? =}
Code:
for i in $( find -name \*JPG ); do echo mv $i $(echo $i|sed -r -e 's/([0-9]{2})-([0-9]{2})-([0-9]{2})/\3\2\1/' -e 's/://g'); done
mv ./eg06_ana_21-05-06_09:21:03.JPG ./eg06_ana_060521_092103.JPG
I ask for help only after having actually tried every single way I know to be able to do something myself.
Thanks a lot for your useful help. It has been accurate and quick!
Quote:
Originally Posted by Tinkster
Code:
$ ls
eg06_ana_21-05-06_09:21:03.JPG
$ for i in $( find -name \*JPG ); do echo mv $i $(echo $i|tr ':' '-'); done
mv ./eg06_ana_21-05-06_09:21:03.JPG ./eg06_ana_21-05-06_09-21-03.JPG
If this does what you expect, just remove the BOLD echo and run it.
[edit]
But while you're at it, why not convert the date to an iso
date so your files sort chronologically? =}
Code:
for i in $( find -name \*JPG ); do echo mv $i $(echo $i|sed -r -e 's/([0-9]{2})-([0-9]{2})-([0-9]{2})/\3\2\1/' -e 's/://g'); done
mv ./eg06_ana_21-05-06_09:21:03.JPG ./eg06_ana_060521_092103.JPG
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.