Created
July 6, 2016 20:12
-
-
Save AaronO/6ea44552fcee5884b17da2ef99c91696 to your computer and use it in GitHub Desktop.
Turns all symlinks in a folder into hardlinks
This file contains hidden or 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 | |
set -o nounset | |
set -o errexit | |
set -o pipefail | |
# Ensure hardlink exists | |
if ! [ $(hardlink --help &> /dev/null; echo $?) = "1" ]; then | |
echo "hardlink command seems to be missing" | |
echo "Please install it" | |
exit 1 | |
fi | |
for folder in $(ls -d ./*/ | sed 's/\/$//'); do | |
# Skip non symlinks | |
if ! readlink ${folder} &> /dev/null; then | |
continue | |
fi | |
destination=$(readlink ${folder}) | |
echo "${folder} -> ${destination}" | |
rm "${folder}" | |
hardlink "${destination}" ${folder} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment