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://codercto.com/courses/l/8.html

查看所有标签

Artificial Intelligence

Artificial Intelligence

Stuart Russell、Peter Norvig / Pearson / 2009-12-11 / USD 195.00

The long-anticipated revision of this #1 selling book offers the most comprehensive, state of the art introduction to the theory and practice of artificial intelligence for modern applications. Intell......一起来看看 《Artificial Intelligence》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

html转js在线工具
html转js在线工具

html转js在线工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具