Python os.link() Method
Python OS File/Directory Methods
Overview
The os.link() method is used to create a hard link named parameter dst, pointing to parameter src.
This method is very useful for creating a copy of an existing file.
It is only supported on Unix and Windows.
Syntax
link()The method syntax is as follows:
os.link(src, dst)
Parameters
src-- The source path used to create the hard link
dst-- The destination path used to create the hard link
Return Value
This method has no return value.
Examples
The following example demonstrates the use of the link() method:
#!/usr/bin/python # -*- coding: UTF-8 -*- 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 output of the above program is:
Hard link created successfully!!Other Extensions