In ubuntu Linux, I have a bunch of abominably broken symlinks like:
$ ls -l setup.conf
lrwxrwxrwx 1 ont ont 27 Aug 19 15:26 setup.conf -> '# Source it'$'\r''. ../setup.conf'
They are the result of an attempt to replace all symlinks in a project with a comment and a source call (". ../setup.conf
") of the target file. They are all really text files (the example containing: "# Source it\n. .../setup.conf
") with the symlink bit. This was done using git and windows.
One theoretical fix would be to just remove the "symlink bit" and keep the resulting textfile as is, but I see no way of doing that (chmod
and other tools sees it as a "dangling symlink" and refuses to operate on the text-file itself).
Another fix would be to manually create a new file, with contents as the above as taken from the ls
command. I'd rather not resort to that, as it is tedious and error prone, and the files are not identical).
EDIT: ADDED:
I want to end up with a regular file named setup.conf whose contents are
"# Source it<newline>. ../setup.conf'
"
# Source it'$'\r''. ../setup.conf'
or if you want to have a file namedsetup.conf
whose contents are# Source it'$'\r''. ../setup.conf'
or something else.find .... -type l -name setup.conf -exec sh -c 'readlink "$1" > "$1.new" && mv "$1.new" "$1"' sh {} +
(untested)