shellcopyspecial-charactersfilenamescp

shell : How to copy recursively also filenames that have specialchar


I'm using a simple script on ubuntu 20.04 to backup important folders on an external disk :

    #!/usr/bin/env bash
    cp -r  /PROFILE PROFILE
    cp -r /media/DATA DATA

It works fine except for some files whose filename contains special character : # | ? and '

The error is "cannot create standard file './DATA/Re: blahblah': Invalid argument" (translated from french langage error message). And the said file is not copied.

When i use rsync -avrq the same filenames also produce errors and arent copied, but rsync is a bit more verbose on errors :

I once had (without the "quiet" option i think) this detail : « rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1207) [sender=3.1.3] »

How can I better use cp -r or rsync or another not-too-complex tool to also backup these files ? I've searched and couldnt find :-/

Could it be that this is related to an issue with my OS install rather than cp or rsync use ? This UBuntu 20.04 has been upgraded from 18.04 and sometimes tweaked.

[EDIT] Destination external HD partition is NTFS (says gparted) or "fuse" (says Nautilus / Properties). I see on Permissions for external HDD nextcloud container that changing it to ext4 could bring a fix to the (code 23) at main.c(1207) [sender=3.1.3] issue.

[EDIT] it looks like rsync uses a temporary file with '.' prefix and some times the issue is with this file and sometime it happens also when moving this file to final destination file (without .) : rsync: rename "/media/jluc/My Passport/SAVRSYNC/logo/.rubon1.ZpK66N" -> "logo/rubon1.": Invalid argument (22)


Solution

  • The only way i found to cp files with specialchar in their name is to copy them to an EXT4 partition instead of NTFS.

    So i reduced the NTFS external HD partition (it required the whole night to do so), created an EXT4 partition (labelled "EXT4ELEM") in the spare space and used it to backup my files : no more errors.

    « cp "#:<>'ENE" /media/jluc/EXT4ELEM » is OK.

    (inspiration found here : Permissions for external HDD nextcloud container)