[Python] python 把文件夹压缩成tar →→→→→进入此内容的聊天室

来自 , 2019-03-16, 写在 Python, 查看 143 次.
URL http://www.code666.cn/view/b0bf8b3d
  1. import tarfile
  2. import os
  3. import sys
  4.  
  5. user =  os.getenv('USERNAME')
  6.  
  7. filename = '/home/%s/tmp.tgz' % user
  8. print 'The tar file was created here: %s' % filename
  9. mode = 'w:gz'
  10.  
  11. file = tarfile.open( filename, mode )
  12.  
  13. file.add( '/var/log/auth.log' )
  14. file.add( '/var/log/messages' )
  15.  
  16. file.close()
  17. print 'done'
  18. #//python/2354

回复 "python 把文件夹压缩成tar"

这儿你可以回复上面这条便签

captcha