I have a shell script on Solaris 9 that has a link to it. I only found out about the link because of documentation. How can I determine if a shell script has a link to it? When I do a find / -name "linkname" -print as root I don't see the linked name show up anywhere? What command do I need to run to see the "linkname"?
Unix OS
Last Comment
jjc_mn
8/22/2022 - Mon
nixfreak
> How can I determine if a shell script has a link to it?
If you want to find the symbolic links that point to the script "/usr/bin/mystery.sh"
find / -type l -ls | awk '{if($13=="/usr/bin/mystery.sh")print$11}'
One comment on the last find command for file by inode number:
The command may return to you multiple files from different file systems, since the inode number is unique within the same file system only.
To be on the safe side:
1- run find on the filesystem by putting its mount dir rather than / with -mount option to limit the search to the same filesystem
to find out filesystems on your server use df -k
e.g if you are searching for a hardlink for a file in /usr/users/user1/bin dir , and when you run df -k you see that there is a filesystem /usr/users, then the modified command will be:
Neither worked! I ran them as su. I know its a link because I can modify the script then run the other command and Ill see my changes.
Heres my OS version: SunOS hostname 5.9 Generic_118558-18 sun4u sparc SUNW,Sun-Fire-V490
My comment was on the hardlink find not the softlink
simple test.
You said that you can modify the first one and run the other and see the changes.
Please do the following
1- do ls -li for both files
do you see the same inode number and the same owner ship number of links and the same size?
If yes, then it is a hardlink and should work.
2- for soft link try
find /usr/users -mount -type l -exec ls -l {} \; | awk '/mystery.sh/ {print$9}'
arthurjb
>>Neither worked! I ran them as su. I know its a link because I can modify the script then run the other command and I see my changes
If I understand this correctly, then you know the name of the link to the script, so here is what you can do.
type;
which name-other-command
this will give you the path to the link, then you can do an;
ls -l /full-pathto/name-other-command
jjc_mn
ASKER
find / -type l -exec ls -l {} \; | grep "mystery.sh" --fails to find anything
ls -li for both files --- finds the known script. Doesn't find the link in the same dir for know link
which command -- Finds "knownscript" doesn't find link
ls -l -rwxr--r-- 1 user staff 1842 Jun 1 14:14 /export/home/user/mystery.sh - shows it as NOT a link yet whenever I modify the "mystery.sh" the link immediately shows the change
a find for the inum only shows "mystery.sh" and other stuff on different partitions but notthe right name.
When you run ls -li on both file names, do you get the same info for:
1- the first 10 chars
2- owner user name
3- owner group name
4- same size
5- same inode number
Do you see a dash (i.e. -) in the first 10 chars or you get l or both? dash means hardlink, l means soft link.
Do you see -> in either of files info? if yes then it is a soft link pointing to the original file.
Try renaming of the files (use mv command). Do you still see the changes and can run both?
jjc_mn
ASKER
I can run ls -li on the script, but I can't run ls -li on the "link" because I can't find the "link" ! I only know the "link" even exists because I saw it in a document. Then I became curious to how one would tell how many aliases were pointing at some file.
I put the word "link" in quotes becuase maybe it's associated in some other way... Though how I wouldn't know.
arthurjb
The tough part is that if it is not really a link, then it could be a call out from a script, or even a sub-script, so there is not really a way to tell.
If the commands given in the other comments for finding links don't work, then it is likely just a program, script, or library used by others.
Can you at least show the ls -li for the file you are updating? This might help us to give us more guidance.
nixfreak
> find / -type l -exec ls -l {} \; | grep "mystery.sh" --fails to find anything
ls -li for both files --- finds the known script. Doesn't find the link in the same dir for know link
which command -- Finds "knownscript" doesn't find link
ls -l -rwxr--r-- 1 user staff 1842 Jun 1 14:14 /export/home/user/mystery.sh - shows it as NOT a link yet whenever I modify the "mystery.sh" the link immediately shows the change
In that case I think there is no sym/hard link to you script. Just my imagination: but there could be another program/script that has the pathname of this script hardcoded in it.
omarfarid
Hi,
Sorry i missed the details of ls -li for the file that you posted before.
But from the info provided, it is a regular file (from the dash) and there is one hard link to it.
I agree with nixfreak that there could be other scripts calling this one, and you may need to use grep for that, or if you have some documentation about the system that may shorten your search to particular files or directories.
I found it!.
At some point a tech added to the login home directory a file called .aliases. In this file he added a line to this effect:
alias elusivefile='/export/home/user/knownfile.sh'
So anytime you enter at the prompt the name 'elusivefile' you actually run 'knownfile.sh'
If you want to find the symbolic links that point to the script "/usr/bin/mystery.sh"
find / -type l -ls | awk '{if($13=="/usr/bin/myster
If you want to find the hardlinks:
find / -inum `ls -i /usr/bin/mystery.sh | awk '{print$1}'`