Python os.link() 方法
Python 教程
· 2019-02-03 23:28:30
概述
os.link() 方法用于创建硬链接,名为参数 dst,指向参数 src。
该方法对于创建一个已存在文件的拷贝是非常有用的。
只支持在 Unix, Windows 下使用。
语法
link()方法语法格式如下:
os.link(src, dst)
参数
src -- 用于创建硬连接的源地址
dst -- 用于创建硬连接的目标地址
返回值
该方法没有返回值。
实例
以下实例演示了 link() 方法的使用:
#!/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 "创建硬链接成功!!"
执行以上程序输出结果为:
创建硬链接成功!!
点击查看所有 Python 教程 文章: https://www.codercto.com/courses/l/8.html
Visual Thinking
Colin Ware / Morgan Kaufmann / 2008-4-18 / USD 49.95
Increasingly, designers need to present information in ways that aid their audiences thinking process. Fortunately, results from the relatively new science of human visual perception provide valuable ......一起来看看 《Visual Thinking》 这本书的介绍吧!