Skip to content

Commit 9e29b2e

Browse files
committedFeb 28, 2024
added find_hardlinks.sh
1 parent 713e014 commit 9e29b2e

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
 

‎bin/find_hardlinks.sh

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
# vim:ts=4:sts=4:sw=4:et
3+
#
4+
# Author: Hari Sekhon
5+
# Date: 2024-02-28 01:16:44 +0000 (Wed, 28 Feb 2024)
6+
#
7+
# https///github.com/HariSekhon/DevOps-Bash-tools
8+
#
9+
# License: see accompanying Hari Sekhon LICENSE file
10+
#
11+
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
12+
#
13+
# https://www.linkedin.com/in/HariSekhon
14+
#
15+
16+
set -euo pipefail
17+
[ -n "${DEBUG:-}" ] && set -x
18+
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
19+
20+
# shellcheck disable=SC1090,SC1091
21+
. "$srcdir/lib/utils.sh"
22+
23+
# shellcheck disable=SC2034,SC2154
24+
usage_description="
25+
Finds all hardlinks to a given file by searching the mount point for the same inode number of a file
26+
"
27+
28+
# used by usage() in lib/utils.sh
29+
# shellcheck disable=SC2034
30+
usage_args="<filename>"
31+
32+
help_usage "$@"
33+
34+
num_args 1 "$@"
35+
36+
filename="$1"
37+
38+
inode_number="$(stat -f "%i" "$filename")"
39+
40+
mount_point="$(df "$filename" | awk '{print $NF}' | tail -n 1)"
41+
42+
find "$mount_point" -xdev -inum "$inode_number" -print

0 commit comments

Comments
 (0)
Please sign in to comment.