Skip to content

Instantly share code, notes, and snippets.

@Saneyan
Created August 24, 2014 09:47
Show Gist options
  • Select an option

  • Save Saneyan/bcfe487c9bea46cc877c to your computer and use it in GitHub Desktop.

Select an option

Save Saneyan/bcfe487c9bea46cc877c to your computer and use it in GitHub Desktop.
Find symlinks or symlinks of original file.
#!/bin/sh
#
# lnfind : Find symlinks or symlinks of original file.
#
# example:
# # When this command prints:
# ls -l $HOME | grep .vimrc # ... /home/user/.vimrc -> /home/user/.vim/vimrc
#
# # it should find like:
# lnfind $HOME .vimrc # Outputs '/home/user/.vimrc'
# lnfind -r $HOME .vimrc # Outputs '/home/user/.vim/vimrc'
#
# lnfind command can reverse lookup with '-r' option.
#
if [ "$1" = "-r" ]; then
dir=$2; tar=$3; reg="s,.*\,,,g"
else
dir=$1; tar=$2; reg="s,\,.*,,g"
fi
find $dir -ls | grep -oE "/.*\s\->.*$" | tr -s " \-> " "," | grep -E $(echo $tar | sed "s,\.,\\\.,g") | sed $reg
unset dir tar reg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment