Results 1 to 5 of 5
Hi All,
I’m trying to copy a large number of files from a Linux server to a Windows file share. Unfortunately, all of the files and folders I have to ...
- 04-01-2009 #1Just Joined!
- Join Date
- Mar 2009
- Posts
- 8
[SOLVED] Change file names to remove invalid character.
Hi All,
I’m trying to copy a large number of files from a Linux server to a Windows file share. Unfortunately, all of the files and folders I have to copy have 10 numbers followed by 2 colons "::" in the name (example: 1234567890::WordDoc.doc) which of course is invalid in windows naming conventions. So now I'm trying to come up with a way to change the file and folder names on the fly to replace the colons with a dash "-" or space " ". I'm even willing delete the frist 12 characters in necessary.
I have tried cp, mv, tr, and several -bash scripts but nothing seems to help.
I'm really desperate at this point and would appreciate any help.
Thanks
Ray LaureynsLast edited by laureynsr; 04-01-2009 at 08:35 PM. Reason: More details
- 04-01-2009 #2
I was just helping someone with this a few weeks ago

You can use a for loop to rename each file in Linux:
Make sure you have backups before trying this though incase it isn't what you wantCode:for filename in `ls` ; do mv $filename `echo $filename | sed s/:://` ; done
You can see the full explanation in this post:http://www.linuxforums.org/forum/sus...files-two.htmlLinux User #453176
- 04-01-2009 #3Just Joined!
- Join Date
- Mar 2009
- Posts
- 8
Hi Kieren,
Thanks for the tip, but I might be missing something. I copied the folder to another location to test and created a tried the command as stated:
for filename in 'ls' ; do mv $filename 'echo $filename | sed s/:://' ; done
I get "mv: cannot stat `ls': No such file or directory" I am running this from the path where the files and folders are.
I know there is a way of doing this even if I have to parse file and foler names so everything to the left of the "::" is deleted.
Thanks
Ray Laureyns
- 04-01-2009 #4
You have wrapped ls in single quotes (') when it should be an apostrophe (`)
apostrophe can be found (on my keyboard anyway) next to the number 1 key. The same is needed around "echo $filename | sed s/:://"
Here is what you have used:
And here is what it should be:Code:for filename in 'ls' ; do mv $filename 'echo $filename | sed s/:://' ; done
Code:for filename in `ls` ; do mv $filename `echo $filename | sed s/:://` ; done
Linux User #453176
- 04-02-2009 #5Just Joined!
- Join Date
- Mar 2009
- Posts
- 8
Kieren,
You are a LIFE SAVER! (My mistake on the single quote vs apostrophe). Worked on 90% of the files and folders accept the ones with spaces in the names or brackets "()". Those (about 85 files) I'm renaming by hand encapsulating in double quotes.
Thank you VERY MUCH for your help!!
Ray


