Latest web development tutorials

Python3 os.link () method

Python3 OS file / directory methods Python3 OS file / directory methods


Outline

os.link () method is used to create a hard link named parameter dst, pointing parameter src.

The method for creating a copy of the existing file is useful.

Only support the use of Unix, Windows under.

grammar

link () method syntax is as follows:

os.link(src, dst)

parameter

  • src - source address is used to create a hard link

  • dst - thedestination address is used to create a hard link

return value

This method has no return value.

Examples

The following examples demonstrate the link () method of use:

#!/usr/bin/python3

import os, sys

# 打开文件
path = "/var/www/html/foo.txt"
fd = os.open( path, os.O_RDWR|os.O_CREAT )

# 关闭文件
os.close( fd )

# 创建以上文件的拷贝
dst = "/tmp/foo.txt"
os.link( path, dst)

print ("创建硬链接成功!!")

The above program output is:

创建硬链接成功!!

Python3 OS file / directory methods Python3 OS file / directory methods