search for hardlinks based on filename via find command

I am using command substitution into a find command in a script where I have built a menu to do a bunch of tasks within my unix account. When I choose the options for to find a file/files that have the same inode of the entered filename, ie hardlinks, nothing shows up. When I choose the appropiate options to build my find command everything looks to be in order. I need to know how do I get the hard links to print out. Below is the segment of the menu that I use to build the find command for the find path -inum filename -print:

echo "\n Select the number of the search primary"

echo "\n 1) Search based on inodes (-inodes via filename)"

echo "\n Choice: \c"
read pchoice

case $pchoice in
1) srch_pri='-inum';;

case $pchoice in
1) echo "Filename: \c";
read srch_arg;;

echo "Select number of the action primary"

echo "\n 1) Display the current pathname (-print)"

echo "\n Choice: \c"
read achoice

case $achoice in
1) act_pri = '-print';;

case $achoice in
1) act_arg='';;

path =$HOME

find $path $srch_pri $srch_arg $act_pri $act_arg

find &ltdir&gt ! -type d -links +1 -ls|sort -n

this will print all hardlinks in specified directory, sorted by files i-node.

the ! -type d is to avoid directories.
The -links +1 will find all files that have MORE than 1 link. Hardlinked files have a link count of at least two.
The -ls is used to view the inode number after find has found the file.

  • The sort -n will sort the list by inode number showing you which files are hardlinked together.

This will only work if your search includes the directories that contain all of the hardlinked files.

here is anotherway

f=`ls -i $srch_arg |awk '{print $1}'`
find / -inum $f

this will search all system and print any files that is hardlinked with $srch_arg

[Edited by mib on 03-25-2001 at 06:05 AM]

Thanks, that helped alot.