1

In Linux, how can I recursively copy files and directories in such a way that all of the copied files and directories will have a name that windows can handle?

I want to copy a folder into a shared directory or USB device that uses Windows file name restrictions, without failing or losing any files/folders (prefer to change name rather than to lose data).

Kamil Maciorowski
  • 69,815
  • 22
  • 136
  • 202
micsthepick
  • 133
  • 1
  • 9
  • If a device "uses Windows file name restrictions", this means the filesystem there uses restrictions. But Windows programs may be more restrictive. Compare [this](https://superuser.com/q/282194/432690) or [this](https://superuser.com/a/585119/432690). Windows itself can handle many problematic names (using `\\?\…`) but this is inconvenient in daily use. Sets of names that "device (filesystem) can hande", "Windows can handle" or "common Windows programs can handle" differ. It's not really clear which one you want. – Kamil Maciorowski Oct 19 '19 at 08:14
  • @KamilMaciorowski I want to copy the files without losing them. I don’t care if they won’t work with some application. – micsthepick Oct 19 '19 at 08:16
  • 1
    But even printing a directory listing or copying files further on Windows is done by "some applications" (e.g. `explorer.exe`). OK, let me rephrase: is Windows involved at all? (what Windows then?) Or you just need to store files on a non-Linux filesystem (what filesystem?) and still use them with Linux only. – Kamil Maciorowski Oct 19 '19 at 08:37

1 Answers1

0

Some ideas from the post copy filenames with special characters to an external ntfs volume:

  • Use detox to clean up special characters in filenames.

  • Mount the NTFS filesystem so it cleans up (sanitizes) the file names by itself. The mount option to enable this is windows_names. See man ntfs-3g.

  • Use rsync to change filenames to fit the destination filesystem with the parameter --iconv=CONVERT_SPEC, to request charset conversion of filenames.

harrymc
  • 455,459
  • 31
  • 526
  • 924