查看inode相关信息
The inode index node is a data structure in a Unix-style file system that describes a file-system object such as a file or a directory. Each inode stores the attributes and disk
The inode index node is a data structure in a Unix-style file system that describes a file-system object such as a file or a directory. Each inode stores the attributes and disk
环境:
工作需要检查相关excel数据信息, 查询一个表格中的指定位置编号,检查相关多个个相关表格中指定位置编号是否相同。 环境 windows10 python3.7 + openpyxl + xlrd 测试数据 目录结构 1 2 3 4 5 6 7 8 9 10 C:. │ checklist.py │ reference.xlsx │ └─newdir ├─dir1 │ data1.xls │ └─dir2 data2.xls 文件内容 参考表格 reference.xlsx A CODE-12345 表格1 data1.xls A CODE-12345 表格2 data2.xlsx A CODE-67890 代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 from openpyxl import load_workbook from openpyxl import Workbook import os import xlrd ## 获取待检查清单列表 def get_file(root_path,all_files=[]): files = os.listdir(root_path) for file in files: if not os.path.isdir(root_path + '/' + file): # 检查文件名包含"功能点", 以 "xls", "xlsx"为后缀的文件 if (file.endswith('.xls') or file.endswith('.xlsx')) \ and 'XXXX' in file: all_files.append(root_path + '/' + file) else: # 如果是目录,目录后增加'/'递归查找符合条件的文件 get_file((root_path+'/'+file),all_files) return all_files ## 获取参考文件指定位置编号 def get_request_no(root_path): files = os.listdir(root_path) for file in files: if not os.path.isdir(root_path + '/' + file): if file.endswith('.xls') or file.endswith('.xlsx') \ and 'YYYY' in file: print (file) ## only xlsx wb_in = load_workbook(file) ws_in = wb_in.active ## 查找第2行,第5列的编号 request_no = ws_in.cell(row=2, column=5) print (request_no.value + '\n') ##break return request_no.value; ## 遍历参考列表文件记录与参考文件表中需求编号不同的文件名 def check_file(files, request_no): result="" for file in files: ## 由于openpyxl, 不支持xls,这里使用的是xlrd库 wb_in = xlrd.open_workbook(file) ws_in = wb_in.sheets()[0] ## 编号是从0开始计数, 第8行, 第2列中的数据 file_request_no = ws_in.cell(rowx=7, colx=1) if str(file_request_no.value) != str(request_no): s = file_request_no.value + file +'\n' result += s return result def write_log(result): file=open("result.txt", "w") file.write(result) file.close() path = r'.\\ZZZZ' list=get_file(path) path = r'.' no=get_request_no(path) result=check_file(list, no) write_log(result) 运行结果 1 2 3 > python check.py > type result.txt CODE-67890.\\newdir/dir2/data2.xls 参考 Openpyxl Doc xlrd- API Reference
文件时间信息一般包含,文件创建时间,文件修改时间,文件访问时间。 Unix/Linux 文件修改时间有两个一个是Modify Time 文件内容修改/ Change Time:文件权限状态/权限, 根据不同的文件系统,文件时间信息属性会有一些差别。Unix/Linux在挂载文件系统的时候会设置相关文件时间属性相关参数。
工作需要修改excel文件创建内容时间(excel属性非文件属性)和上次修改时间, 用python写了一个脚本处理了一下。 环境: windows10 python3.7 + openpyxl 1. 使用openpyxl修改excel属性 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import openpyxl from datetime import datetime fh = openpyxl.load_workbook("results.xlsx") obj = fh.properties #To get old properties print( obj ) # print old properties fh.properties.created = datetime(2000,1,1, 8,30,11) fh.properties.modified = datetime(2000,2,1, 8,32,19) ##similarly you can set other fields ## new_obj = fh.properties #Now get new properties print ( new_obj ) # print new properties fh.save("results2.xlsx") 2.使用os.utime方法修改文件属性的访问时间,修改时间 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import os, sys,time from datetime import datetime # Showing stat information of file stinfo = os.stat('results.xlsx') print (stinfo) # Using os.stat to recieve atime and mtime of file print ("access time of results.xlsx: %s" %stinfo.st_atime) print ("modified time of results.xlsx: %s" %stinfo.st_mtime) # Modifying atime and mtime t = datetime(2008, 1, 1, 12,12, 12) atime = time.mktime(t.timetuple()) t = datetime(2009, 1, 1, 12,12, 12) mtime = time.mktime(t.timetuple()) os.utime("results.xlsx",(atime, mtime)) print ("done!!") 3.使用pywin32-SetFileTime方法修改文件属性的创建日期, 访问时间,修改时间 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 from win32file import CreateFile, SetFileTime, GetFileTime, CloseHandle from win32file import GENERIC_READ, GENERIC_WRITE, OPEN_EXISTING from pywintypes import Time import time from datetime import datetime def modifyFileTime(filePath, createTime, modifyTime, accessTime): try: fh = CreateFile(filePath, GENERIC_READ | GENERIC_WRITE, 0, None, OPEN_EXISTING, 0, 0) createTimes = Time(createTime) accessTimes = Time(modifyTime) modifyTimes = Time(accessTime) print (createTimes, accessTimes, modifyTimes) SetFileTime(fh, createTimes, accessTimes, modifyTimes) CloseHandle(fh) return 0 except: return 1 if __name__ == '__main__': t = datetime (2019, 12,13,21,51,2) cTime = time.mktime(t.timetuple()) t = datetime (2019, 2,2,0,1,3) mTime = time.mktime(t.timetuple()) t = datetime (2019, 2,2,0,1,4) aTime = time.mktime(t.timetuple()) fName = r"results.xlsx" r = modifyFileTime(fName, cTime, mTime, aTime) if r == 0: print('修改完成') elif r == 1: print('修改失败') 参考及引用 Openpyxl Doc python 修改文件的创建时间、修改时间、访问时间 pythondoc-os.utime In Python, how do you convert a datetime object to seconds? python ImportError: No module named win32file
cenos7X86_64
环境: cenos7(X86_64) + openssh ssh端口配置 修改端口 例如8888 文件 /etc/ssh/sshd_config 1 2 #Port 22 Port 8888 重启服务 1 2 systemctl restart sshd systemctl status sshd 防火墙配置: 我这里配置比较简单仅zone配置了一个public 1 firewall-cmd --permanent --zone=public --add-port=8888/tcp 重启服务 1 2 systemctl restart firewalld systemctl status firewalld
上周在学习单点登录安装CAS Overlay Template要使用指定版本,当时机器上安装了多个版本的jdk使用alternatives命令进行了切换
可以通过磁盘分区和文件两种方式进行操作
/proc/buddyinfo 文件可以查看Linux机器上可用的内存页, 可以查看每个节点,不同区域的每个order大小的块的可用数量, 下面是我们虚拟机的信息: