Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- set -e
- for link; do
- test -h "$link" || continue
- dir=$(dirname "$link")
- reltarget=$(readlink "$link")
- case $reltarget in
- /*) abstarget=$reltarget;;
- *) abstarget=$dir/$reltarget;;
- esac
- rm -fv "$link"
- cp -afv "$abstarget" "$link" || {
- # on failure, restore the symlink
- rm -rfv "$link"
- ln -sfv "$reltarget" "$link"
- }
- done
- -H (c and r mode only) Symbolic links named on the command line will
- be followed; the target of the link will be archived, not the
- link itself.
- tar -hcf - sourcedir | tar -xf - -C newdir
- tar --help:
- -H, --format=FORMAT create archive of the given format
- -h, --dereference follow symlinks; archive and dump the files they point to
- find / -maxdepth 2 -type l -print
- find / -maxdepth 2 -type l -exec ./ReplaceSymLink.sh {} ;
- find . -type l -exec cp --dereference --recursive '{}' '{}'.dereferenced ;
- find . -type l -exec bash -c "echo 'Replacing {} ...'; cp -LR '{}' '{}'.dereferenced; rm '{}'; mv '{}'.dereferenced '{}'" ;
- for i in *; do link=$(readlink $i) && rm $i && mv $link $i; done
- "for file in `ls`; do cp -L $file scratchdir/$file; done; mv scratchdir/* ./"
- before:
- > find . -type l | wc -l
- 358
- > for link in `find . -type l` ; do echo "$link : "; ls -al $link ; cp $link notalink; unlink $link; mv notalink $link ; ls -al $link; done
- ...
- after:
- > find . -type l | wc -l
- 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement