Last active
March 27, 2020 11:45
-
-
Save PrometheusPi/b89edba472d919334c9f2f9a27a7232a to your computer and use it in GitHub Desktop.
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 | |
| # go through all symbolic links | |
| for i in `find . -type l` | |
| do | |
| # get absolute path behind link | |
| export realFile=$(readlink -f $i) | |
| # capture symlinks pointing nowhere | |
| if [ -z $realFile ] | |
| then | |
| # TODO: push this to stderr >&2 in front does not work | |
| echo warning: symlink $i has no target | |
| else | |
| # verbose output to user | |
| echo replacing $i with $realFile | |
| # remove link (could als be done by rm) | |
| unlink $i | |
| # copy original file to symlink location | |
| # add -r flag to copy directory if symlink points to a directory | |
| cp -r $realFile $i | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment