LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Replace ":" from multiple files names (even recursively in directories) (https://www.linuxquestions.org/questions/linux-general-1/replace-from-multiple-files-names-even-recursively-in-directories-786050/)

pepeq 01-31-2010 04:45 PM

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.


Thanks a lot.

Tinkster 01-31-2010 05:50 PM

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

[/edit]



Cheers,
Tink

pepeq 02-01-2010 10:27 AM

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 (Post 3847628)
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

[/edit]



Cheers,
Tink


Tinkster 02-01-2010 11:09 AM

Quote:

Originally Posted by pepeq (Post 3848456)
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!

That's just my signature - not part of the post.


Cheers,
Tink


P.S.: Please don't top-post with quotes.


All times are GMT -5. The time now is 12:09 AM.