unlink (Unix)

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
unlink
Repository
  • {{URL|example.com|optional display text}}Lua error in Module:EditAtWikidata at line 29: attempt to index field 'wikibase' (a nil value).
Engine
    Lua error in Module:EditAtWikidata at line 29: attempt to index field 'wikibase' (a nil value).
    Operating systemUnix and Unix-like
    PlatformCross-platform
    TypeCommand

    In Unix-like operating systems, unlink is a system call and a command line utility to delete files. The program directly interfaces the system call, which removes the file name and (but not on GNU systems) directories like rm and rmdir.[1] If the file name was the last hard link to the file, the file itself is deleted as soon as no program has it open.[2]

    Unlike the rm utility, the unlink utility only accepts one argument, which can be desirable to guard against accidental multi-deletions.[3]

    It also appears in the PHP, Node.js, R, Perl and Python standard libraries in the form of the unlink() built-in function. Like the Unix utility, it is also used to delete files.[4][5][6][7]

    Examples

    [edit | edit source]

    To delete a file named foo, one could type:

    % unlink foo
    

    In PHP, one could use the following function to do the same:

    unlink("foo");
    

    The Perl syntax is identical to the PHP syntax, save for the parentheses:

    unlink "foo";
    

    In Node.js it is almost the same as the others:

    fs.unlink("foo", callback);
    

    In R (with the S language compatibility):

    unlink("foo") 
    #Comment: using the inside argument 'recursive = TRUE', directories can be deleted
    

    Similarly in Python:

    os.unlink("foo")
    

    See also

    [edit | edit source]

    References

    [edit | edit source]
    1. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    2. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    3. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    4. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    5. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    6. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    7. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).