Skip to content

Instantly share code, notes, and snippets.

@wpcarro
Created September 23, 2019 15:41
Show Gist options
  • Select an option

  • Save wpcarro/5f174f9eb8a01e1a49187dcfea17e6cf to your computer and use it in GitHub Desktop.

Select an option

Save wpcarro/5f174f9eb8a01e1a49187dcfea17e6cf to your computer and use it in GitHub Desktop.
Expand symlinks into their source; delete the symlink.
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