Python3 Os Link
# Python3.x Python3 os.link() Method
[ Python3 OS File/Directory Methods](#)
* * *
### Overview
The os.link() method is used to create a hard link named dst that points 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/python3import os, sys # Open a file path = "/var/www/html/foo.txt" fd = os.open( path, os.O_RDWR|os.O_CREAT )# Close the 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!!
[ Python3 OS File/Directory Methods](#)
YouTip