I have a number of files with characters such as $'\351'
and $'\346'
. I haven't figured out how to reference these files on bash. How can I use mv
and sed
to change their names?
When I run ls
, one of the files that appears, for example, is shown as:
'根'$'\346''%8B'$'\240''.html'
Most users in this situation would want to use convmv
to convert the encoding of such filenames.
However, since you don't really know or care what the original filename was supposed to be but just want a reversible transformation to make the names easier to deal with, you could rename all files to a hexdump of their bytes:
export LC_ALL=C
for f in *
do
mv -- "$f" "$(printf '%s' "$f" | od -t x1 -An | tr -cd 'a-f0-9')"
done
This will e.g. turn the file '根'$'\346''%8B'$'\240''.html'
into e6a0b9e6253842a02e68746d6c