Skip to content

Instantly share code, notes, and snippets.

@staroselskii
Last active August 29, 2015 13:57
Show Gist options
  • Save staroselskii/9830782 to your computer and use it in GitHub Desktop.
Save staroselskii/9830782 to your computer and use it in GitHub Desktop.
#!/usr/bin/ksh
IFS="`printf ''`"
USAGE="usage: symlink.sh <file>"
get_metadata() {
perl -se 'use File::stat; $file=lstat($filename); if (defined $file) { print $file->ctime . " " . $file->ino . "\n"; } ' -- -filename="$1"
}
readlink() {
perl -se 'use File::Spec; print File::Spec->rel2abs( readlink($file) )' -- -file="$1"
}
abs_path() {
perl -se 'use File::Spec; print File::Spec->rel2abs( $file)' -- -file="$1"
}
if [ $# -eq 0 ]; then
echo "$USAGE"
exit 1
fi
FILE_NAME=$(abs_path "$1")
echo "Result:"
for LINK in ./* ./.[!.]* ;do
if [ -L "$LINK" ]; then
TARGET=$(readlink "$LINK")
if [ ! -z "$TARGET" ]; then
if [[ "$FILE_NAME" = "$TARGET" ]]; then
get_metadata "$LINK"
fi
fi
fi
done | sort -nk1 | awk '{print $2}' | xargs -IX find . -inum X | egrep '.*' || echo "No such files"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment