LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-02-2014, 05:59 AM   #1
Seb Spiers
LQ Newbie
 
Registered: Mar 2012
Location: Worcester, UK
Distribution: Fedora, CentOS
Posts: 18

Rep: Reputation: Disabled
Remove non-windows characters from file names


I've been given an external HDD from a customer which he's populated using an Apple workstation and many of the files and folders contain colons [:] which Windows obviously dislikes and won't make use of so I need to replace them with full stops [.].

Can anyone advise me of the simplest way to recursively go through a directory structure finding and replacing any folder or file with a colon [:] in it replacing it with a full stop [.]?
 
Old 09-02-2014, 06:16 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 5,266
Blog Entries: 12

Rep: Reputation: 1862Reputation: 1862Reputation: 1862Reputation: 1862Reputation: 1862Reputation: 1862Reputation: 1862Reputation: 1862Reputation: 1862Reputation: 1862Reputation: 1862
I'm assuming you can mount this on a Linux system and see the files?

From the top level of that disk, you probably have to use sudo or perform that as root to account for varied file ownership.

Code:
find . -name "*:*" -exec rename 's/:/./' {} \;
 
Old 09-02-2014, 07:34 AM   #3
Seb Spiers
LQ Newbie
 
Registered: Mar 2012
Location: Worcester, UK
Distribution: Fedora, CentOS
Posts: 18

Original Poster
Rep: Reputation: Disabled
Just the job, thanks!
 
Old 09-02-2014, 02:29 PM   #4
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 350

Rep: Reputation: 151Reputation: 151
Does it ever happen that the filename contains two or more colons? If so, append g (as in global) to the expression in order to replace all:
Code:
find . -name "*:*" -exec rename 's/:/./g' {} \;
 
Old 09-03-2014, 03:28 AM   #5
Seb Spiers
LQ Newbie
 
Registered: Mar 2012
Location: Worcester, UK
Distribution: Fedora, CentOS
Posts: 18

Original Poster
Rep: Reputation: Disabled
Yeah I did that, thanks for the help guys.
 
Old 09-24-2014, 07:49 PM   #6
maples
Member
 
Registered: Oct 2013
Location: IN, USA
Distribution: Arch, Debian Jessie
Posts: 813

Rep: Reputation: 264Reputation: 264Reputation: 264
Just thought that I'd throw this out there-- someone else might come along with a similar situation (like I did)

You can replace the colon and the period with any single character, and it works just fine. I just used it to replace spaces with underscores. Just make sure that you change BOTH colons.

Hope this helps!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Special characters in file names Jinouchi Linux - Newbie 7 07-25-2009 11:48 AM
non-Latin characters in file names -Pb- Linux - Newbie 4 11-15-2007 06:48 AM
cannot read cyrillic characters in file names hazylama Linux - Software 6 05-01-2007 07:59 PM
Replacing characters in file names? yuccabrevifolia Linux - Software 1 04-19-2006 01:31 PM
rename file names with " ? characters fishbonz Linux - Newbie 2 05-31-2005 11:20 AM


All times are GMT -5. The time now is 06:04 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration