I have a directory tree with many .dat files, where many of them contain special characters. They are used by another process which is only able to process files containing ascii characters.
My idea was to find
all the files, build a new file name based on the md5
hash of their file path, and copy them to a new directory (they aren't very large, and I may not alter the originals).
This is what I've tried
find dat -type f -name "*.dat" -print0|xargs -0 -I file cp 'file' "datnew/$(echo file|md5).dat"
Unfortuntately it only builds a single hash, and copy all files to that output file name:
$ touch dat/foo.dat
$ touch dat/bar.dat
$ find dat -type f -name "*.dat" -print0|xargs -0 -I file cp 'file' "datnew/$(echo file|md5).dat"
$ ls datnew
bbe02f946d5455d74616fc9777557c22.dat
Can you please tell me what my mistakte is? Am I using xargs
in a wrong way?
echo file | md5
? It should bebbe02f946d5455d74616fc9777557c22
asfile
will not be interpreted in$( echo file | md5 )
file
there to be replaced as well?-n1
to thexargs
command.