文件的复制与移动 import shutil(导入模块) 1、shutil.copyfileobj(源文件管家,目标文件管家):只能复制文件内容,不能复制权
fr = open('/etc/hosts',mode='r')
fw = open('/opt/myhosts',mode='w')
shutil.copyfileobj(fr,fw)
fr.close()
fw.close()
2、shutil.copyfile(src,dst):只能复制文件内容,不能复制权限
shutil.copyfile('/usr/bin/ls','/opt/myls')
3、shutil.copy(src,dst):文件内容与权限都复制
shutil.copy('/usr/bin/ls','/opt/myls01')
4、shutil.move(src,dst):移动;重命名
shutil.move('/opt/myls01','/opt/myls001')