Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
You should avoid such names even under Linux (especially *). – cYrus Jan 29 '11 at 14:43
@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
@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 '15 at 6:42

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

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
Detox is for making Windows files Unix-friendly, not the other way around. – endolith Feb 20 '11 at 2:12
@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 '15 at 16:48
Do note the change in syntax when going to Linux, that is rena '*.*' -portable, and if you want it recursive use something like rena '***/*.*' -portable on Linux. And I do believe the rename should be done on Linux, not on Windows. – holroy Jul 19 '15 at 2:09

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 '15 at 2:07

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .