Python 模拟cp操作

1.创建~/bin/cp.py
2.将/bin/ls "拷贝"到/root/目录xia
3.要求读取/bin/ls后,每次读取4096字节,一次写入到新文件
4.不要修改原始文件
 
#/usr/bin/env python

sfname = open('/bin/ls')
dfname = open('/tmp/ls','w')

while True:
    data = sfname.read(4069)
    if not data:
        break
    dfname.write(data)

sfname.close()
dfname.close()

[root@localhost ~]# md5sum  /tmp/ls
062551aec6c44f228777fde0ea992a65  /tmp/ls
[root@localhost ~]# md5sum  /bin/ls
062551aec6c44f228777fde0ea992a65  /bin/ls

 

posted @ 2017-03-16 14:34  Time.catcher  阅读(2496)  评论(0编辑  收藏  举报