Os Link
# Python2.x Python os.link() Method
[ Python OS File/Directory Methods](#)
* * *
### Overview
The os.link() method is used to create a hard link named dst pointing to src.
This method is very useful for creating a copy of an existing file.
It is only supported on Unix and Windows.
### Syntax
The syntax for the **link()** method is as follows:
os.link(src, dst)
### Parameters
* **src** -- The source address for creating the hard link.
* **dst** -- The destination address for creating the hard link.
### Return Value
This method does not return a value.
### Example
The following example demonstrates the use of the link() method:
#!/usr/bin/python# -*- coding: UTF-8 -*-import os, sys # Open file path = "/var/www/html/foo.txt" fd = os.open( path, os.O_RDWR|os.O_CREAT )# Close file os.close( fd )# Create a copy of the above file dst = "/tmp/foo.txt" os.link( path, dst)print "Hard link created successfully!!"
The output of executing the above program is:
Hard link created successfully!!
[ Python OS File/Directory Methods](#)
YouTip