Convert symlinks to files
Posted by gregster on 17 Apr 2012 in R & D
Had a directory with millions of symlinks. I needed to move the directory without the dependencies imposed by the symlinks. What I wanted was to 'convert' the symlinks to actual files - that is, replace the symlink with a copy of its target file. Found this, which worked a treat. Here's the actual code:
#!/bin/bash
for file in *;
do
link=$(readlink "${file}");
if [ "${link}" ]
then
rm "${file}";
cp -v "${link}" "${file}";
fi;
done;