0
点赞
收藏
分享

微信扫一扫

linux中文件复制的代码实现2.py

#文件的复制2.py

def copy(source,destination):#source源文件,destination想复制到的位置

 file_read1 = open(source,mode="rb")

 file_write1 = open(destination,mode="wb")

 while True:

     data = file_read1.read(4096)

     if len(data) == 0:

         break

     file_write1.write(data)

 file_read1.close()

 file_write1.close()

 print("完成")

copy("/etc/hostname","/opt/hostname")

接下来试一试效果

[root@node1 day3]# ls /opt/

1.txtx  registries.conf

[root@node1 day3]# python3 copy.py

完成

[root@node1 day3]# ls /opt/

1.txtx  hostname  registries.conf

[root@node1 day3]# cat /opt/hostname

node1

举报

相关推荐

0 条评论