-
-
Save hatsuyuki15/397fe02d5dc394924b8ab35fa23a1b20 to your computer and use it in GitHub Desktop.
This script will allow you to effectively hard link a directory. It reproduces the directory structure of the source in the destination and then recursively hard links all the files from the source to the corresponding location in the destination. If you've ever wanted to hard link a folder, this produces the results you want.
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 | |
oldifs=$IFS | |
IFS=' | |
' | |
[ $# -ne 2 ] && { echo "Usage: $0 sourceDirectory destinationDirectory" ; exit 1; } | |
[ ! -d "$1" ] && { echo "$1 is not a valid directory"; exit 1; } | |
[ ! -d "$2" ] && { mkdir -p "$2"; } | |
src=$(cd "$1" ; pwd) | |
dst=$(cd "$2" ; pwd) | |
find "$src" -type d | | |
while read dir; do | |
mkdir -p "$dst${dir#$src}" | |
done | |
find "$src" -type f -o -type l | | |
while read src_f; do | |
dst_f="$dst${src_f#$src}" | |
ln "$src_f" "$dst_f" | |
done | |
IFS=$oldifs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment