I have a bunch of directory, sub-directory, and filenames that were created in Linux with the following pattern: YYYY - MM - DD T HH : MM : SS (I added spaces for clarity but no spaces are in the directory/sub/file names; YYYY, MM, DD... are integers and '-', 'T', ':' are constants of the expression).
These directories/files were copied to Windows and then back to Linux, and the ':' got corrupted. Each place where there should be ':' there is '\357\200\242' which shows up as ??? when I do ls
.
I know that fixing this should not be too complicated using a combination of mv
and sed
, but I'm very rusty on my piping, regex, and sed
usage.
So far I have this
for a in *T*???*???*; do mv "$(echo "$a" | sed [***])"; done
The [***]
should be a regex that changes *T*???*???*
to *T*:*:*
where the middle two *
are each two digits. And this should rename both files and directories, recursively. I also suspect that ???
is not the correct input pattern to use here.
Alternate approach
I've seen a bunch of posts offering a combination of find
and rename
, but again, I am a bit rusty on the use of regex, and could not arrive at a good solution for this situation.