Python os.link() Method
os.link() Overview
The os.link() method is used to create a hard link named with the argument dst, pointing to the argument src.
This method is very useful for creating a copy of an existing file.
It is only supported for use under Unix, Windows.
os.link() Syntax
The syntax format of the link() method is as follows:
os.link(src, dst)
os.link() Parameters
- src – the source address used to create the hard connection
- dst – the destination address used to create the hard connection
os.link() Return Value
This method has no return value.
os.link() Demo#1
The following example demonstrates the use of the link() method:
#!/usr/bin/python3
import os, sys
# open file
path = "/root/apidemos.com.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/apidemos.com.txt"
os.link( path, dst)
print ("Create hard link successfully!!!")
Output: