Created
October 10, 2010 12:08
-
-
Save arnold-almeida/619188 to your computer and use it in GitHub Desktop.
Convert symlinks to hard links in a dir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# For recursive operation, I saved the script below to this location: "/usr/local/bin/symtohard". | |
# Any directory in your $PATH will work just fine. After putting it there, make sure to run: | |
# | |
# chmod +x /usr/local/bin/symtohard | |
# | |
# Converts all symbolic links in a directory to hard links. See http://ubuntuforums.org/showthread.php?t=1508728 for any updates/problems. | |
# | |
# Run via cmd below without [] | |
# | |
# [find /directory_with_syms -type l -exec dirname '{}' \; | sort | uniq | xargs -L 1 -I {} symtohard "{}"] | |
# | |
# | |
if [ -d "$1" ] ; then | |
echo "About to convert all symlinks in '$1' " | |
# if [ "$confirm" == "y" ]; then | |
cd "$1" && | |
FOLDER="*" | |
for file in $FOLDER | |
do | |
if [ -L "$file" ]; then | |
target=$(readlink "$file") | |
echo "Converting link to $file" | |
mv "$file" "$file.old" && | |
ln "$target" "$file" && | |
rm "$file.old" | |
else | |
echo "$file not a symlink, skipping" | |
fi | |
done | |
# else | |
# echo "Exiting. No changes made." | |
# fi | |
else | |
echo "$1 is not a directory, exiting." | |
fi | |
exit |
Even simplier solution from http://superuser.com/questions/560597/convert-symlinks-to-hard-links
find -type l -exec bash -c 'ln -vf "$(readlink -m "$0")" "$0"' {} ;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The real trick is converting back to a symlink again... About the most efficient way I've found involves using rsync...