LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 01-31-2010, 04:45 PM   #1
pepeq
Member
 
Registered: Aug 2004
Location: Spain
Distribution: opensuse 11
Posts: 51

Rep: Reputation: 15
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.
 
Old 01-31-2010, 05:50 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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

Last edited by Tinkster; 01-31-2010 at 05:56 PM.
 
1 members found this post helpful.
Old 02-01-2010, 10:27 AM   #3
pepeq
Member
 
Registered: Aug 2004
Location: Spain
Distribution: opensuse 11
Posts: 51

Original Poster
Rep: Reputation: 15
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 View Post
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
 
Old 02-01-2010, 11:09 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by pepeq View Post
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.
 
  


Reply

Tags
batch, characters, files, recursive, rename, replace



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying files and sub-directories of a directory except the directories named ".abc" sri1025 Linux - General 2 08-24-2010 08:53 AM
Recursively add missing ".jpg" to all JPEG files. Chekote Linux - General 4 09-14-2009 11:45 PM
can't recursively copy directories/files with non-ascii names on freeNAS Rascale *BSD 2 03-30-2009 01:07 PM
shell script to recursively "compare" all files in a directory... silex_88 Programming 3 05-12-2007 04:24 AM
copying multiple different files in different directories with identical file names nickleus Linux - Software 4 03-09-2006 01:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration