Just curious: why is /usr/bin/python not a symlink?

Discussion in 'Python' started by HoneyMonster, Feb 23, 2012.

  1. HoneyMonster

    HoneyMonster Guest

    $ cd /usr/bin
    $ ls -l python*
    -rwxr-xr-x 2 root root 9496 Oct 27 02:42 python
    lrwxrwxrwx 1 root root 6 Oct 29 19:34 python2 -> python
    -rwxr-xr-x 2 root root 9496 Oct 27 02:42 python2.7
    $ diff -s python python2.7
    Files python and python2.7 are identical
    $

    I'm just curious: Why two identical files rather than a symlink?
    HoneyMonster, Feb 23, 2012
    #1
    1. Advertising

  2. On Thu, 23 Feb 2012 19:11:16 +0000, HoneyMonster wrote:

    (reformatted (I hope)

    > $ cd /usr/bin
    > $ ls -l python*
    > -rwxr-xr-x 2 root root 9496 Oct 27 02:42 python
    > lrwxrwxrwx 1 root root 6 Oct 29 19:34 python2 -> python
    > -rwxr-xr-x 2 root root 9496 Oct 27 02:42 python2.7
    > $ diff -s python python2.7
    > Files python and python2.7 are identical
    > $
    >
    > I'm just curious: Why two identical files rather than a symlink?


    Sorry, my first post didn't format properly.
    Colin Higwell, Feb 23, 2012
    #2
    1. Advertising

  3. HoneyMonster

    Jerry Hill Guest

    On Thu, Feb 23, 2012 at 2:11 PM, HoneyMonster <> wrote:
    > $ cd /usr/bin
    > $ ls -l python*
    > -rwxr-xr-x 2 root root 9496 Oct 27 02:42 python
    > lrwxrwxrwx 1 root root    6 Oct 29 19:34 python2 -> python
    > -rwxr-xr-x 2 root root 9496 Oct 27 02:42 python2.7
    > $ diff -s  python python2.7
    > Files python and python2.7 are identical
    > $
    >
    > I'm just curious: Why two identical files rather than a symlink?


    It's not two files, it's a hardlink. You can confirm by running ls
    -li python* and comparing the inode numbers.

    --
    Jerry
    Jerry Hill, Feb 23, 2012
    #3
  4. HoneyMonster

    Chris Rebert Guest

    On Thu, Feb 23, 2012 at 11:11 AM, Colin Higwell
    <> wrote:
    > $ cd /usr/bin
    > $ ls -l python*
    > -rwxr-xr-x 2 root root 9496 Oct 27 02:42 python
    > lrwxrwxrwx 1 root root    6 Oct 29 19:34 python2 -> python
    > -rwxr-xr-x 2 root root 9496 Oct 27 02:42 python2.7
    > $ diff -s  python python2.7
    > Files python and python2.7 are identical
    > $
    >
    > I'm just curious: Why two identical files rather than a symlink?


    Depends on your distro / installation method:
    $ ls -l python*
    lrwxrwxrwx 1 root root 9 Apr 12 2011 python -> python2.6
    -rwxr-xr-x 1 root root 2288272 Dec 27 2010 python2.6
    $ # this is on my Debian server

    Cheers,
    Chris
    Chris Rebert, Feb 23, 2012
    #4
  5. HoneyMonster

    HoneyMonster Guest

    On Thu, 23 Feb 2012 14:24:23 -0500, Jerry Hill wrote:

    > On Thu, Feb 23, 2012 at 2:11 PM, HoneyMonster
    > <> wrote:
    >> $ cd /usr/bin $ ls -l python*
    >> -rwxr-xr-x 2 root root 9496 Oct 27 02:42 python lrwxrwxrwx 1 root root
    >>    6 Oct 29 19:34 python2 -> python -rwxr-xr-x 2 root root 9496 Oct 27
    >> 02:42 python2.7 $ diff -s  python python2.7 Files python and python2.7
    >> are identical $
    >>
    >> I'm just curious: Why two identical files rather than a symlink?

    >
    > It's not two files, it's a hardlink. You can confirm by running ls -li
    > python* and comparing the inode numbers.


    You are spot on. Thank you, and sorry for my stupidity.
    HoneyMonster, Feb 23, 2012
    #5
  6. HoneyMonster

    Jerry Hill Guest

    On Thu, Feb 23, 2012 at 2:34 PM, HoneyMonster <> wrote:
    > On Thu, 23 Feb 2012 14:24:23 -0500, Jerry Hill wrote:
    >> It's not two files, it's a hardlink.  You can confirm by running ls-li
    >> python* and comparing the inode numbers.

    >
    > You are spot on. Thank you, and sorry for my stupidity.


    I don't think you're stupid. It's hard to tell the difference between
    two separate files with the same file size and a hardlink. The
    biggest clue is the number "2" in the second column. If I recall
    correctly, for directories, that's the number of entries in the
    directory. For files, that number is the number of hardlinks
    referring to that file.

    Even with that, it's hard to tell what files are hardlinked together,
    and figuring it out by inode is a pain in the neck. Personally, I
    prefer symlinks, even if they introduce a small performance hit.
    Readability counts, even in the filesystem.

    --
    Jerry
    Jerry Hill, Feb 23, 2012
    #6
  7. HoneyMonster

    Terry Reedy Guest

    On 2/23/2012 2:34 PM, HoneyMonster wrote:
    > On Thu, 23 Feb 2012 14:24:23 -0500, Jerry Hill wrote:
    >
    >> On Thu, Feb 23, 2012 at 2:11 PM, HoneyMonster
    >> <> wrote:
    >>> $ cd /usr/bin $ ls -l python*
    >>> -rwxr-xr-x 2 root root 9496 Oct 27 02:42 python lrwxrwxrwx 1 root root
    >>> 6 Oct 29 19:34 python2 -> python -rwxr-xr-x 2 root root 9496 Oct 27
    >>> 02:42 python2.7 $ diff -s python python2.7 Files python and python2.7
    >>> are identical $
    >>>
    >>> I'm just curious: Why two identical files rather than a symlink?

    >>
    >> It's not two files, it's a hardlink. You can confirm by running ls -li
    >> python* and comparing the inode numbers.

    >
    > You are spot on. Thank you, and sorry for my stupidity.


    The question 'why a hardlink rather than symlink' is not stupid. It was
    part of the discussion of http://python.org/dev/peps/pep-0394/
    The answer was 'history' and how things were 20 years ago and either the
    pep or the discussion around it says symlinks are fine now and the
    decision is up to distributors.

    --
    Terry Jan Reedy
    Terry Reedy, Feb 23, 2012
    #7
  8. Am 23.02.2012 20:54 schrieb Jerry Hill:

    > If I recall
    > correctly, for directories, that's the number of entries in the
    > directory.


    No. It is the number of subdirectories (it counts their ".." entries)
    plus 2 (the parent directory and the own "." entry).


    > Even with that, it's hard to tell what files are hardlinked together,
    > and figuring it out by inode is a pain in the neck. Personally, I
    > prefer symlinks, even if they introduce a small performance hit.


    Not only that, they have slightly different semantics. With hardlinks
    you can say "I want this file, no matter if someone else holds it as
    well". Symlinks say "I want the file which is referred to by there".

    In the given case, however, this difference doesn't count, and I agree
    on you that a symlink would be better here.


    Thomas
    Thomas Rachel, Feb 24, 2012
    #8
  9. HoneyMonster

    Roy Smith Guest

    In article <ji7fbd$drj$>,
    Thomas Rachel
    <>
    wrote:

    > Not only that, [hard and symbolic links] have slightly different
    > semantics.


    This is true, but only for very large values of "slightly".

    Symlinks, for example, can cross file system boundaries (including NFS
    mount points). Symlinks can refer to locations that don't exist! For
    example:

    ~$ ln -s foobar foo
    ~$ ls -l foo
    lrwxr-xr-x 1 roy staff 6 Feb 24 08:15 foo -> foobar
    ~$ cat foo
    cat: foo: No such file or directory

    Symlinks can be chained (i.e. a symlink points to someplace which in
    turn is another symlink). They're really very different beasts.
    Roy Smith, Feb 24, 2012
    #9
  10. HoneyMonster

    John Roth Guest

    On Feb 23, 2:11 pm, Terry Reedy <> wrote:
    > On 2/23/2012 2:34 PM, HoneyMonster wrote:
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > > On Thu, 23 Feb 2012 14:24:23 -0500, Jerry Hill wrote:

    >
    > >> On Thu, Feb 23, 2012 at 2:11 PM, HoneyMonster
    > >> <>  wrote:
    > >>> $ cd /usr/bin $ ls -l python*
    > >>> -rwxr-xr-x 2 root root 9496 Oct 27 02:42 python lrwxrwxrwx 1 root root
    > >>>     6 Oct 29 19:34 python2 ->  python -rwxr-xr-x 2 root root 9496 Oct 27
    > >>> 02:42 python2.7 $ diff -s  python python2.7 Files python and python2.7
    > >>> are identical $

    >
    > >>> I'm just curious: Why two identical files rather than a symlink?

    >
    > >> It's not two files, it's a hardlink.  You can confirm by running ls -li
    > >> python* and comparing the inode numbers.

    >
    > > You are spot on. Thank you, and sorry for my stupidity.

    >
    > The question 'why a hardlink rather than symlink' is not stupid. It was
    > part of the discussion ofhttp://python.org/dev/peps/pep-0394/
    > The answer was 'history' and how things were 20 years ago and either the
    > pep or the discussion around it says symlinks are fine now and the
    > decision is up to distributors.
    >
    > --
    > Terry Jan Reedy


    I believe the changes for PEP 394 are using symlinks. The distro
    maintainer can, of course, change that.

    John Roth
    John Roth, Feb 24, 2012
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Salerno
    Replies:
    30
    Views:
    1,941
    Stephan Kuhagen
    Aug 10, 2006
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,762
    Smokey Grindel
    Dec 2, 2006
  3. Yves Dorfsman

    #!/usr/bin/env python vs. #!/usr/bin/python

    Yves Dorfsman, May 2, 2008, in forum: Python
    Replies:
    27
    Views:
    1,974
    Tim Roberts
    May 10, 2008
  4. anne001
    Replies:
    1
    Views:
    402
  5. Gilles
    Replies:
    7
    Views:
    544
    Matej Cepl
    Sep 30, 2012
Loading...

Share This Page