What is the difference between unlink and rm? - Unix

This is a discussion on What is the difference between unlink and rm? - Unix ; Both command can delete a file, whats the difference? Thanks....

+ Reply to Thread
Results 1 to 7 of 7

Thread: What is the difference between unlink and rm?

  1. What is the difference between unlink and rm?

    Both command can delete a file, whats the difference?

    Thanks.


  2. Re: What is the difference between unlink and rm?

    "Bin Chen" writes:

    > Both command can delete a file, whats the difference?


    unlink is a system call, rm is a shell utility that calls unlink.

    --
    M錸s Rullg錼d
    mans@mansr.com

  3. Re: What is the difference between unlink and rm?

    M錸s Rullg錼d writes:

    > "Bin Chen" writes:
    >
    >> Both command can delete a file, whats the difference?

    >
    > unlink is a system call, rm is a shell utility that calls unlink.


    Ah, now I remember there also (at least in the GNU package) an
    "unlink" executable. It appears to be a simple wrapper for the unlink
    system call, taking a single file argument only. It's purpose is not
    clear to me.

    --
    M錸s Rullg錼d
    mans@mansr.com

  4. Re: What is the difference between unlink and rm?

    On Apr 16, 10:27 am, "Bin Chen" wrote:
    > Both command can delete a file, whats the difference?
    >
    > Thanks.


    In the GNU system `unlink' can never delete the name of a directory.
    Also unlink is unfriendly with wild cards.

    -Cheers,
    Gunvant
    ~~~~~~~~
    No trees were killed in the sending of this message. However a large
    number of electrons were terribly inconvenienced.


  5. Re: What is the difference between unlink and rm?

    In article ,
    M錸s Rullg錼d wrote:

    > M錸s Rullg錼d writes:
    >
    > > "Bin Chen" writes:
    > >
    > >> Both command can delete a file, whats the difference?

    > >
    > > unlink is a system call, rm is a shell utility that calls unlink.

    >
    > Ah, now I remember there also (at least in the GNU package) an
    > "unlink" executable. It appears to be a simple wrapper for the unlink
    > system call, taking a single file argument only. It's purpose is not
    > clear to me.


    On some flavors of Unix, unlink can delete things that rm can't, such as
    directories, if you're running as superuser.

    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    *** PLEASE don't copy me on replies, I'll read them in the group ***

  6. Re: What is the difference between unlink and rm?

    On 4月16日, 下午9时41分, "Gunvant Patil" wrote:
    > On Apr 16, 10:27 am, "Bin Chen" wrote:
    >
    > > Both command can delete a file, whats the difference?

    >
    > > Thanks.

    >
    > In the GNU system `unlink' can never delete the name of a directory.
    > Also unlink is unfriendly with wild cards.


    So the underlying principle is exact the same except some
    functionality lost in unlink?


  7. Re: What is the difference between unlink and rm?

    >> > Both command can delete a file, whats the difference?
    >>
    >> > Thanks.

    >>
    >> In the GNU system `unlink' can never delete the name of a directory.
    >> Also unlink is unfriendly with wild cards.

    >
    >So the underlying principle is exact the same except some
    >functionality lost in unlink?


    In the ancient past, creating a directory consisted of three steps
    (now done with mkdir()):

    1. create an empty directory node with mknod().
    2. Link (hard) a "." entry to that directory node.
    3. Link (hard) a ".." entry to the directory's parent.

    Removing a directory consisted of three steps (now done with rmdir(),
    which also does some type checks first):

    1. unlink() the ".." entry
    2. unlink() the "." entry
    3. unlink() the directory itself

    unlink (run as root) would remove a name entry regardless of its type.

    With a combination of link() and unlink() you could do all sorts
    of evil things to the directory tree by repointing "." and ".."
    entries. You could also orphan subtrees that take disk space but
    have no references from the outside.


+ Reply to Thread