Script to convert ext4 filenames to NTFS

ext4 allows certain chars in filenames which NTFS doesn't. Is there a script to replace those chars in filenames?


Solution 1:

The following should replace all disallowed characters in filenames with underscores. Note that this may cause multiple files to be renamed to the same thing. For example, if you had two files called file>/txt and file<.txt, both will be renamed to file_.txt, and one will overwrite the other, deleting it.

find /path/to/ntfs/mount/ -print0 | xargs -0 rename 's{[\\:*?"<>|]}{_}g'

This command is valid for the perl version of rename, which is what Debian provides. Your distro may provide a version of rename with a slightly different syntax.