Created
September 23, 2019 15:41
-
-
Save wpcarro/5f174f9eb8a01e1a49187dcfea17e6cf to your computer and use it in GitHub Desktop.
Expand symlinks into their source; delete the symlink.
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
| deref() { | |
| # Dereferences a symlink. | |
| # Usage: deref [symlink] | |
| if ! [ -L $1 ]; then | |
| echo_error "File is not a symlink: $1. Exiting..." | |
| else | |
| local src=$(readlink -f $1) | |
| echo "Moving $src -> $1" && \ | |
| mv $1 $1.bak && \ | |
| mv $src $1 && \ | |
| rm $1.bak | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment