环境:linux
编程语言:python
版本:Python 2.6.6 (r266:84292, Apr 11 2011, 15:52:27)
(1)如何获取指定文件的属主:
def getowner(path2):
import os
import pwd
return pwd.getpwuid(os.stat(path2).st_uid).pw_name
(2)如何递归列出指定目录的所有file(不包括目录):
def listfiles(path2):
import os
tmp=os.walk(path2)
full_files=[]
for root,dirs, files in tmp:
for file in files:
full_files.append(os.path.join(root,file))
return full_files
(3)如何获取指定文件的权限,如755
def get_power(path3):
'''
path3 is directory or regular file
'''
import os
return oct(os.stat(path3)[0])[-3:]
(4)如何设置权限
(类似于 chmod 755 /home/user2)
def chmod(path4,str_power):
import os
if not os.path.exist(path4):
return 4 #file does not exist
os.chmod(path4,int(str_power,8))
分享到:
相关推荐
一些PYTHON常用库 一些PYTHON常用库 一些PYTHON常用库
python常用函数超详细总结pdf文档,常用的函数使用说明、高阶函数使用说明
Python常用英文单词
python常用数据集 鸢尾花数据集.csv
Python必备常⽤英语词汇 适合对英文单子不熟悉的小白,每日晨读与日常多操作,多敲多用,也就记住了
python常用代码技巧,备忘
Python常用库大全
python 常用语句 常用模块, 常用语法, 可以当成参考资料, 编程的时候查看
学习python时经常要用到一些模块,这个文件里有python常用模块详解
该程序包含7大排序算法: # sort.bubbleSort() #冒泡排序 # sort.shellSort() #希尔排序 # sort.insertionSort() #插入排序 # sort.Selectionsort1() #选择排序 # sort.heapSort() #堆排序 ...
python常用模块.pdf
9大Python常用技巧!干货满满!.docx9大Python常用技巧!干货满满!.docx9大Python常用技巧!干货满满!.docx9大Python常用技巧!干货满满!.docx9大Python常用技巧!干货满满!.docx9大Python常用技巧!干货满满!....
python 常用方法 python最常用函数
ArcGIS Python常用脚本 日常经常用到的arcpy源码 来源网络 仅整理
python大数据入门数据集.txtpython大数据入门数据集.txtpython大数据入门数据集.txtpython大数据入门数据集.txtpython大数据入门数据集.txtpython大数据入门数据集.txtpython大数据入门数据集.txtpython大数据入门...
python常用方法utils
1.beautifulsoup4-4.5.1.tar 2.beautifulsoup4-4.5.1.tar 3.chardet-3.0.4-py2.py3-none-any 4.cssselect-1.1.0-py2.py3-none-any 5.idna-2.8-py2.py3-none-any 6.lxml-4.5.2-cp36-cp36m-win_amd64 ...
数学建模30个常用算法(Python)数学建模30个常用算法(Python)数学建模30个常用算法(Python)数学建模30个常用算法(Python)数学建模30个常用算法(Python)数学建模30个常用算法(Python)数学建模30个常用算法...
通过分析github上5000多个开源python项目,找出最常用的库,例如os、os.path、glob、sys、re、logging、subprocess、time、datetime、urllib、random、telnetlib、paramiko
粗糙集属性约简代码python