TCL的file命令

最近,看到redis自己的测试代码,于是简单了解一下,总结一下file命令的简单实用,不废话,上代码

最近,看到redis自己的测试代码,于是简单了解一下,总结一下file命令的简单实用,不废话,上代码

#!/usr/bin/tclshset path $argv0# atime: 以UNIX时间戳形式,返回/设置文件的访问时间puts "atime: [file atime $path]"# 返回/设置文件属性信息puts "attributes: [file attributes $path]"# 返回单个文件属性信息puts "attibutes, permission: [file attributes $path -permission]"# 设置单个文件属性set ret [file attributes $path -permission 00777]puts "attibutes, set permission: [file attributes $path -permission]"# 查看文件信息unset retfile stat $path retputs "file stat: "parray ret# 删除文件file delete a.txtputs "del file, name: a.txt"# 复制文件file copy $path a.txtputs "copy file, src: $path, dst: a.txt"# 复制文件,但是文件已存在则覆盖file copy -force $path a.txtputs "force copy file, src: $path, dst: a.txt"# 连续--用于预设参数部分结束,后续全是文件名,用于文件名以-开头的字符串file copy -force $path -a.txtfile copy -force -- -a.txt xxx.txt# 删除文件/目录file delete -force -- a.txt -a.txt xxx.txt puts "delete file"# 级联创建目录file mkdir X/XX/XXXputs "mkdir X/XX/XXX"# 返回原生路径,不识别文件是否存存在unset retset ret [file nativename ~/ok/fish.txt]puts "native, source: ~/ok/fish.txt, native: $ret"# 返回文件绝对路径,唯一标准化路径unset retset ret [file normalize $path]puts "normalize, source: $argv0, native: $ret"# 返回目录名称unset retset ret [file dirname [file normalize $path]]puts "dirname, path: [file normalize $path], dir: $ret"# 验证文件是否可执行puts "path exec? path: $path, exec: [file executable $path]"# 验证文件是否存在puts "path exists? path: $path, exist: [file exists $path]"# 返回文件扩展名puts "path extension, path: $path, extension: [file extension $path]"# 检查是否是目录set dir [file dirname [file normalize $path]]puts "is dir? path: $dir, isdir: [file isdirectory $dir]"# 创建链接set linkfile file.lnfile delete -force $linkfilefile link -symbolic $linkfile $pathputs "create link, src: $path, dst: $linkfile, return link source file: [file readlink $linkfile]"# 符号链接信息,链接本身,非链接指向的文件unset retset linkfile file.lnfile lstat $linkfile retputs "symbol: "parray ret# 多个字符串串成路径puts "join str: [file join xxx yyy zzz ddd wu]"# 判定是否是文件puts "is file: [file isfile $path]"# 返回通道puts "channels: [file channels], match channels: [file channels "*err"]"# 创建具有临时读写权限的文件, 当前不支持# unset ret# file tempfile ret "fish.tmp"# puts "temp file: $ret"# 返回修改时间puts "path: $path, mtime: [file mtime $path]"# 文件大小,单位: Bputs "path: $path, size: [file size $path]"# 文件系统puts "path: $path, file system: [file system $path]"# 是否文件所有者puts "path: $path, file owned: [file owned $path]"# 相对路径、绝对路径、volumerelative判断puts "path: $path, abs: [file normalize $path], re: [file pathtype $path], abs: [file pathtype [file normalize $path]]"# 重命名、移动、同名覆盖# file rename X Y# 返回rootname,仅仅去掉后缀名,意义在哪?puts "rootname, path: $path, rootname: [file rootname [file normalize $path]]"# 拆分路径puts "split path, path: [file normalize $path], split: [file split [file normalize $path]]"# 路径最后一个部分puts "path tail, path: [file normalize $path], tail: [file tail [file normalize $path]]"# 路径分隔符puts "file separator: [file separator]"# 卷puts "volumes: [file volumes]"# 类型, 还有可能是socketputs "type, [file type $path]"# 可读,可写权限puts "path: $path, read: [file readable $path], writable: [file writable $path]"

执行结果

fh@Feihu-3 learn % ./run.tclatime: 1636212405attributes: -group staff -owner fh -permissions 00777 -readonly 0 -creator {} -type {} -hidden 0 -rsrclength 0attibutes, permission: 00777attibutes, set permission: 00777file stat:ret(atime)   = 1636212405ret(blksize) = 4096ret(blocks)  = 8ret(ctime)   = 1636212604ret(dev)     = 16777222ret(gid)     = 20ret(ino)     = 22849742ret(mode)    = 33279ret(mtime)   = 1636212403ret(nlink)   = 1ret(size)    = 3815ret(type)    = fileret(uid)     = 501del file, name: a.txtcopy file, src: ./run.tcl, dst: a.txtforce copy file, src: ./run.tcl, dst: a.txtdelete filemkdir X/XX/XXXnative, source: ~/ok/fish.txt, native: /Users/fh/ok/fish.txtnormalize, source: ./run.tcl, native: /Users/fh/fh_data/workspace/tcl/learn/run.tcldirname, path: /Users/fh/fh_data/workspace/tcl/learn/run.tcl, dir: /Users/fh/fh_data/workspace/tcl/learnpath exec? path: ./run.tcl, exec: 1path exists? path: ./run.tcl, exist: 1path extension, path: ./run.tcl, extension: .tclis dir? path: /Users/fh/fh_data/workspace/tcl/learn, isdir: 1create link, src: ./run.tcl, dst: file.ln, return link source file: ./run.tclsymbol:ret(atime)   = 1636212604ret(blksize) = 4096ret(blocks)  = 0ret(ctime)   = 1636212604ret(dev)     = 16777222ret(gid)     = 20ret(ino)     = 22858687ret(mode)    = 41453ret(mtime)   = 1636212604ret(nlink)   = 1ret(size)    = 9ret(type)    = linkret(uid)     = 501join str: xxx/yyy/zzz/ddd/wuis file: 1channels: stdin stdout stderr, match channels: stderrpath: ./run.tcl, mtime: 1636212403path: ./run.tcl, size: 3815path: ./run.tcl, file system: nativepath: ./run.tcl, file owned: 1path: ./run.tcl, abs: /Users/fh/fh_data/workspace/tcl/learn/run.tcl, re: relative, abs: absoluterootname, path: ./run.tcl, rootname: /Users/fh/fh_data/workspace/tcl/learn/runsplit path, path: /Users/fh/fh_data/workspace/tcl/learn/run.tcl, split: / Users fh fh_data workspace tcl learn run.tclpath tail, path: /Users/fh/fh_data/workspace/tcl/learn/run.tcl, tail: run.tclfile separator: /volumes: /type, filepath: ./run.tcl, read: 1, writable: 1fh@Feihu-3 learn %

文档参考:

https://www.tcl-lang.org/man/tcl8.6/TclCmd/file.htm

内容来源网络,如有侵权,联系删除,本文地址:https://www.230890.com/zhan/76790.html

(0)

相关推荐