How hardlinked commands work - Linux

This is a discussion on How hardlinked commands work - Linux ; Hi All, We know lots of commands hardlinked with same i-node, they have different file names, and they work in different ways and have different parameters. Also those commands are exactly same when we compare them. Who can let me ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: How hardlinked commands work

  1. How hardlinked commands work

    Hi All,

    We know lots of commands hardlinked with same i-node, they have different
    file names, and they work in different ways and have different
    parameters. Also those commands are exactly same when we compare them.

    Who can let me know how it works in this way. Thanks

    Jeff

  2. Re: How hardlinked commands work

    Jeff Fan wrote:
    > We know lots of commands hardlinked with same i-node, they have different
    > file names, and they work in different ways and have different
    > parameters. Also those commands are exactly same when we compare them.
    >
    > Who can let me know how it works in this way. Thanks


    Overly simplistic for the real world, but it should give you the idea:

    jbuchana@nemo$ ls -li foo bar quux
    3352225 -rwxr-xr-x 3 jbuchana jbuchana 239 Sep 1 21:03 bar
    3352225 -rwxr-xr-x 3 jbuchana jbuchana 239 Sep 1 21:03 foo
    3352225 -rwxr-xr-x 3 jbuchana jbuchana 239 Sep 1 21:03 quux
    jbuchana@nemo$ cat foo
    #!/usr/bin/perl -w

    if ($0 =~ /foo/)
    {
    print "I was called as 'foo'\n";
    }
    elsif ($0 =~ /bar/)
    {
    print "I was called as 'bar'\n";
    }
    else
    {
    print "I was called as something other than 'foo' or 'bar'\n";
    }
    jbuchana@nemo$

    --
    Jim Buchanan jbuchana@buchanan1.net jbuchana@yahoo.com
    =================== http://www.buchanan1.net/ ==========================
    "Remember that if computers are networked, they can talk to each other.
    That is useful when you make an example of one." -ASR faq
    ================= Visit: http://www.thehungersite.com ==================

  3. Re: How hardlinked commands work

    Jeff Fan wrote:
    > Hi All,
    >
    > We know lots of commands hardlinked with same i-node, they have different
    > file names, and they work in different ways and have different
    > parameters. Also those commands are exactly same when we compare them.
    >
    > Who can let me know how it works in this way. Thanks


    ~/code/hl $ cat hl.c
    #include

    int main(int argc, char *argv[])
    {
    if (argc > 0)
    {
    if (strcmp(argv[0],"aaa") == 0)
    printf("You ran this program as \"aaa\"\n");
    else if (strcmp(argv[0],"bbb") == 0)
    printf("You ran this program as \"bbb\"\n");
    else
    printf("You ran this program as \"%s\"\n",argv[0]);
    }
    else
    printf("Gaak!! No programname supplied\n");

    return 0;
    }

    ~/code/hl $ cc hl.c
    ~/code/hl $ ls
    a.out hl.c

    ~/code/hl $ ln a.out aaa
    ~/code/hl $ ln a.out bbb
    ~/code/hl $ ls
    a.out aaa bbb hl.c

    ~/code/hl $ ./a.out
    You ran this program as "./a.out"

    ~/code/hl $ ./aaa
    You ran this program as "./aaa"

    ~/code/hl $ ./bbb
    You ran this program as "./bbb"

    ~/code/hl $

    --
    Lew Pitcher

    Master Codewright and JOAT-in-training
    Registered Linux User #112576 (http://counter.li.org/)
    Slackware - Because I know what I'm doing.


+ Reply to Thread