You are not logged in.

#1 2021-07-22 15:12:47

pezmarino
Member
Registered: 2015-07-24
Posts: 27

How to copy files with unusual simbols

I have a external HD formatted in Ntfs, and I tried to copy in other external HD but there are errors with some directories, for example some files has a blank space in the end  of the name or two points " : " . In the past I copy this files with Unison, a program to synchronize data, but there is another form to do that?

Offline

#2 2021-07-22 17:41:41

NorPhi
Member
From: North rhine-Westphalia
Registered: 2015-08-26
Posts: 10

Re: How to copy files with unusual simbols

If you escape those characters, they should not pose a problem, forbidden are only / and the null character.

I would use rsync to move them, something like : rsync -aAXu SOURCE DESTINATION

Offline

#3 2021-07-22 17:55:14

teckk
Member
Registered: 2013-02-21
Posts: 589

Re: How to copy files with unusual simbols

Use single or double quotes around the file names with non allowed characters.

touch '!@#abc?:;'

file '!@#abc?:;'
!@#abc?:;: empty

ls -l '!@#abc?:;'
-rw-r--r-- 1 me me 0 Jul 22 12:46 '!@#abc?:;

echo "hello" > '!@#abc?:;'

cat '!@#abc?:;'
hello

rm '!@#abc?:;'

On a FAT file system, some chars are not allowed, period.

Such as

/var/cache/pacman/pkg/python-setuptools-1:56.0.0-1-any.pkg.tar.zst

You can't copy that file to a little FAT formated usb drive. Not without a rename.

Offline

#4 2021-07-22 20:06:25

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,424

Re: How to copy files with unusual simbols

Actually the filename limitation is win32, not ntfs - you can mount ntfs in a way that it permits "\:*"?<>|" in filenames, but not access them from windows (so it's generally a dumb idea)
You can use https://archlinux.org/packages/community/x86_64/detox/ to sanitize filenames or fix them on the fly w/ bash variable substitutions or tr,

echo sick | tr is uf

Offline

#5 2021-07-22 21:04:37

pezmarino
Member
Registered: 2015-07-24
Posts: 27

Re: How to copy files with unusual simbols

I tried: rsync -avu but it fails. Doing cp " file " when there are many files, it requires a lot of time. Detox  is a good idea but fails when son files are linked to a file, and changing the name brokes the link.

Offline

#6 2021-07-22 21:56:08

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,424

Re: How to copy files with unusual simbols

Doing cp " file " when there are many files, it requires a lot of time.

Do you object the overhead of creating individual cp processes for every file or did you mean "typing cp '/src/foo:bar' '/dst/foo_bar' for 1000 files will take me 1000 minutes"?
In the latter case, you'd just need a script to recurse over the source path, some "dirname" and "mkdir -p" magic and eg. "$(echo $src_name | tr '\:*"?<>|' '_.+q()-')" …

Offline

#7 2021-07-24 13:05:38

pezmarino
Member
Registered: 2015-07-24
Posts: 27

Re: How to copy files with unusual simbols

seth wrote:

Doing cp " file " when there are many files, it requires a lot of time.

Do you object the overhead of creating individual cp processes for every file or did you mean "typing cp '/src/foo:bar' '/dst/foo_bar' for 1000 files will take me 1000 minutes"?
In the latter case, you'd just need a script to recurse over the source path, some "dirname" and "mkdir -p" magic and eg. "$(echo $src_name | tr '\:*"?<>|' '_.+q()-')" …

Thank you is very good idea, but I don't now how to do a script. When I gottime I will try to learn.

Offline

Board footer

Powered by FluxBB