Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a bunch of files on a Ubuntu box, which have various characters in their filenames that Windows doesn't accept (mostly ":" and "*", but possibly others).

What's the simplest way to get these all renamed and moved to a Windows machine? It's OK to replace these characters with something like "[colon]" and "[asterisk]".

share|improve this question
1  
You should avoid such names even under Linux (especially *). –  cYrus Jan 29 '11 at 14:43
4  
@cYrus Depends on how you handle files. I imagine it's only an issue with scripting and in shells. I'm on OS X and the only forbidden character is :, which is bad enough. Naming documents after their contents is useful, and if an article name ends with a question, so should the file name. –  Daniel Beck Jan 29 '11 at 14:49
    
@cYrus and I do, in my software, but some software has been written by people who don't. For example, qmail uses : in almost every filename it creates. –  romkyns Jan 29 '11 at 14:55
    
@Daniel Beck: Sure, but unfortunately having a file system that supports such names it's not enough as you can use programs that mess the whole thing. I don't even use spaces. –  cYrus Jan 29 '11 at 14:56
2  
@Steven good question! I think Windows would be slightly more useful, as it may happen that someone receives the files on Windows and has to fix them on that platform. –  Peltier Jul 15 at 6:42

4 Answers 4

Try Recuva.

It is the the only Windows utility I have found which handles non-Windows friendly filenames.

Enable Scan for non-deleted files (for recovery from damaged or reformatted disks) and scan your folder. On restore, enable Restore folder structure. Recuva will effectively "copy" the entire directory to another location while "santitizing" unfriendly filenames.

share|improve this answer

Without being on Linux and without testing anything, I believe that one could use one-liners like the ones below.

To change one character :

find . -type f -exec rename 's/:/\[colon\]/g' {} +
find . -type f -exec rename 's/\*/\[asterisk\]/g' {} +

And finally to remove all non-alphanumeric characters :

find . -type f -exec rename 's/[^A-Za-z0-9._]//g' {} +
share|improve this answer
    
Do note that this needs to be extended with all the other illegal characters of windows, i.e.<>:"/\|?* –  holroy Jul 19 at 2:07

Take a look at Glindra rename and detox.

Glindra file utilities can be installed on either Windows or Linux. Examples of cleaning up file names on Windows:

rena *.* -portable

rena *.* -safe
  • -safe
    Maps leading dashes (hyphens) to underscores.
    Collapses spaces.
    Maps problematic characters like *?:[]"<>|(){} to underscore.
  • -portable
    Performs the same cleanup operations as -safe, and additionally:
    Maps all 8-bit characters from the upper half of the Latin 1 alphabet to reasonable 7-bit fallback characters.
    Maps the single quote characters '`´ to underscore.

Source: Fixing Unix/Linux/POSIX Filenames: Control Characters (such as Newline), Leading Dashes, and Other Problems

share|improve this answer
    
That page shows a 404. Google cached copy. –  Daniel Beck Jan 29 '11 at 15:44
    
That is one awesome rant by David Wheeler! Especially after I had just bashed my keyboard after trying to cd into a directory which JungleDisk named "~\irina". Wanna guess whether tab completion worked on it?... –  romkyns Jan 29 '11 at 16:02
1  
Detox is for making Windows files Unix-friendly, not the other way around. –  endolith Feb 20 '11 at 2:12
    
@DennisWilliamson - While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. –  Ramhound Jul 13 at 12:43
3  
@DennisWilliamson - It seems like glindra (for Windows) cannot rename characters with invalid filenames. G:\spc>rena.exe -safe -portable *.txt outputs [FATAL-ERROR] Filename syntax error: aa:a.txt –  Steven Jul 15 at 16:48

If your files already are on an NTFS volume, it seems that running chkdisk from Windows "solves" the problem. Unfortunately, it seems like it does so by deleting the offending files.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.