LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   symbolic link (https://www.linuxquestions.org/questions/slackware-14/symbolic-link-273351/)

ilnli 01-03-2005 12:56 PM

symbolic link
 
root@DARKSTAR:~# ls -l /usr/bin/updatedb
lrwxrwxrwx 1 root root 7 2005-01-02 00:18 /usr/bin/updatedb -> slocate*
root@DARKSTAR:~#

this is my updatedb file which is simply a symbolic to slocate
but when I directly execute slocate it show different behaviour but when I execute it with updatedb it show different, how is that possible???
if it is so then what type of link is this and how can i create such type of links?

Linux~Powered 01-03-2005 01:29 PM

slocate uses the updatedb database to for file searching. It indexes files on your box
ln -s to make a link. man ln

slakmagik 01-03-2005 03:34 PM

Additionally, as I understand it, a program will check for its invocation. So if you invoke it as 'slocate' $0 is 'slocate' and it runs its default way. If you invoke it as updatedb, that points to slocate, so that's what is invoked but, at the same time, $0 is 'updatedb' - slocate can check for that and say, "Ah, I'm supposed to be running as 'slocate -u'" and does so.

But this is pretty much hardcoded. If you want it to run with a different set of default options, you need a shellscript wrapper or alias or the like instead of a symlink.

ilnli 01-04-2005 12:40 AM

anyone else with some more details

DaHammer 01-04-2005 02:08 AM

As digiot stated, the slocate program reads the arguments it's called with (and the program name is always the first argument) and runs appropiately depending on how it's called. So if you run updatedb, you are essentially running "slocate -u". See "man updatedb". It's essentially a programming trick. Alot of linux utilities use it, gzip for example, calling gunzip is the same as calling "gzip -d" on alot of machines. Busybox is another example, in that it emulates alooooot of utils based on the name of the command it's called as.

perfect_circle 01-04-2005 04:09 AM

Code:

[skalkoto@localhost src]$ cat samplecode
#! /bin/bash
                                                                                                                           
if [ ${0##*/} == "samplecode" ]
then    echo "Do this"
else    echo "Do that"
fi
                                                                                                                           
[skalkoto@localhost src]$ ln -s samplecode link_to_samplecode
[skalkoto@localhost src]$ ls -l samplecode link_to_samplecode
lrwxrwxrwx  1 skalkoto skalkoto 10 Jan  4 12:08 link_to_samplecode -> samplecode
-rwxr-xr-x  1 skalkoto skalkoto 91 Jan  4 11:59 samplecode
[skalkoto@localhost src]$ ./samplecode
Do this
[skalkoto@localhost src]$ ./link_to_samplecode
Do that
[skalkoto@localhost src]$

This is a script but u may do the same in C or any other programming languages, since all languages offer a way to get input arguments and the first argument is the name of the file you execute. When you use a software link the name of the link is considered as the name of the file and not the name of the actual executable file.

I don't know if slackware use console-helper. It's an indirect way for a simple user to execute programs that need root privileges.
For example in fedora kppp.
there is an /sbin/kppp and there is a /bin/kppp.
the /sbin directory is not in the path of the simple user.
on the other hand /bin/kppp is a link to console-helper.
Every time a simple user executes kppp the consolehelper will pop-up a window were the user is asked to type the root password. If the password is correct then /sbin/kppp is executed.

ringwraith 01-04-2005 05:05 PM

most of these questions could have been answered by reading "man slocate" and "man updatedb" part of developing slacktitude is learning to find answers to questions by reading a bit. Don't take this as a flame, just pointing out that you should always read the man pages and /usr/doc and then move on to searching these forums.


All times are GMT -5. The time now is 02:46 AM.