Easy Tutorial
❮ Python Func Number Sqrt Python Func Enumerate ❯

Python3 os.link() Method

Python3 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 supported on Unix and Windows systems.

Syntax

The syntax for the link() method is as follows:

os.link(src, dst)

Parameters

Return Value

This method does not return any value.

Example

The following example demonstrates the use of the link() method:

#!/usr/bin/python3

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!!")

Executing the above program outputs:

Hard link created successfully!!

Python3 OS File/Directory Methods

❮ Python Func Number Sqrt Python Func Enumerate ❯