Skip to content

Instantly share code, notes, and snippets.

@arnold-almeida
Created October 10, 2010 12:08
Show Gist options
  • Save arnold-almeida/619188 to your computer and use it in GitHub Desktop.
Save arnold-almeida/619188 to your computer and use it in GitHub Desktop.
Convert symlinks to hard links in a dir
@docbill
Copy link

docbill commented Mar 7, 2014

Something simplier:

find . -type l -print0|xargs -0 -r -n 100 bash -c 'for i in "$@"; do ( j=$(readlink "$i");cd "$(dirname "$i")";[ -f "$j" ] && cp -flv "$j" "$(basename "$i")" );done'

@docbill
Copy link

docbill commented Mar 7, 2014

The real trick is converting back to a symlink again... About the most efficient way I've found involves using rsync...

@docbill
Copy link

docbill commented Mar 7, 2014

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