Skip to content

Instantly share code, notes, and snippets.

@ayuLiao
Last active November 14, 2018 07:38
Show Gist options
  • Select an option

  • Save ayuLiao/9bb072b7e6b55ec8ee729867575493ac to your computer and use it in GitHub Desktop.

Select an option

Save ayuLiao/9bb072b7e6b55ec8ee729867575493ac to your computer and use it in GitHub Desktop.
python修改文件或文件夹权限
def modify_permiss(self, path, name,R=True):
'''
change file or directory permission
:param name: linux user name\
:param R: Recursive modify permission
:return:
'''
idshell = 'id %s'%(name)
code, output = self.execshell(idshell)
if 'No such' not in output:
uid = re.findall('uid=(.*?)\(', output)[0]
gid = re.findall('gid=(.*?)\(', output)[0]
gname = re.findall('\((.*?)\)', output)[1]
if R:
chownshell = 'chown -R %s:%s %s'%(name, gname, path)
code, output = self.execshell(chownshell)
else:
os.chown(path, int(uid), int(gid))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment