Last active
January 28, 2020 14:10
-
-
Save jfollmann/8404a91fde540414854382c67492d67a to your computer and use it in GitHub Desktop.
Script to find hard links in linux
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 | |
# Reference: https://superuser.com/a/12976 | |
if [[ $# -lt 1 ]] ; then | |
echo "Usage: findhardlinks <fileOrDirToFindFor> ..." | |
exit 1 | |
fi | |
while [[ $# -ge 1 ]] ; do | |
echo "Processing '$1'" | |
if [[ ! -r "$1" ]] ; then | |
echo " '$1' is not accessible" | |
else | |
numlinks=$(ls -ld "$1" | awk '{print $2}') | |
inode=$(ls -id "$1" | awk '{print $1}' | head -1l) | |
device=$(df "$1" | tail -1l | awk '{print $6}') | |
echo " '$1' has inode ${inode} on mount point '${device}'" | |
find ${device} -inum ${inode} 2>/dev/null | sed 's/^/ /' | |
fi | |
shift | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment