`
deepfuture
  • 浏览: 4428213 次
  • 性别: Icon_minigender_1
  • 来自: 湛江
博客专栏
073ec2a9-85b7-3ebf-a3bb-c6361e6c6f64
SQLite源码剖析
浏览量:80290
1591c4b8-62f1-3d3e-9551-25c77465da96
WIN32汇编语言学习应用...
浏览量:70776
F5390db6-59dd-338f-ba18-4e93943ff06a
神奇的perl
浏览量:103931
Dac44363-8a80-3836-99aa-f7b7780fa6e2
lucene等搜索引擎解析...
浏览量:287378
Ec49a563-4109-3c69-9c83-8f6d068ba113
深入lucene3.5源码...
浏览量:15119
9b99bfc2-19c2-3346-9100-7f8879c731ce
VB.NET并行与分布式编...
浏览量:68260
B1db2af3-06b3-35bb-ac08-59ff2d1324b4
silverlight 5...
浏览量:32502
4a56b548-ab3d-35af-a984-e0781d142c23
算法下午茶系列
浏览量:46241
社区版块
存档分类
最新评论

perl-stat和lstat

阅读更多

stat

<!-- -->
  • stat FILEHANDLE

     

  • stat EXPR
  • stat DIRHANDLE
  • stat

    Returns a 13-element list giving the status info for a file, either the file opened via FILEHANDLE or DIRHANDLE, or named by EXPR. If EXPR is omitted, it stats $_ . Returns a null list if the stat fails. Typically used as follows:

    1. ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
    2. $atime,$mtime,$ctime,$blksize,$blocks)
    3. = stat($filename);

    Not all fields are supported on all filesystem types. Here are the meanings of the fields:

    1. 0 dev device number of filesystem
    2. 1 ino inode number
    3. 2 mode file mode (type and permissions)
    4. 3 nlink number of (hard) links to the file
    5. 4 uid numeric user ID of file's owner
    6. 5 gid numeric group ID of file's owner
    7. 6 rdev the device identifier (special files only)
    8. 7 size total size of file, in bytes
    9. 8 atime last access time in seconds since the epoch
    10. 9 mtime last modify time in seconds since the epoch
    11. 10 ctime inode change time in seconds since the epoch (*)
    12. 11 blksize preferred block size for file system I/O
    13. 12 blocks actual number of blocks allocated

    (The epoch was at 00:00 January 1, 1970 GMT.)

    (*) Not all fields are supported on all filesystem types. Notably, the ctime field is non-portable. In particular, you cannot expect it to be a "creation time", see "Files and Filesystems" in perlport for details.

    If stat is passed the special filehandle consisting of an underline, no stat is done, but the current contents of the stat structure from the last stat, lstat, or filetest are returned. Example:

    1. if (-x $file && (($d) = stat(_)) && $d < 0) {
    2. print "$file is executable NFS file\n";
    3. }

    (This works on machines only for which the device number is negative under NFS.)

    Because the mode contains both the file type and its permissions, you should mask off the file type portion and (s)printf using a "%o" if you want to see the real permissions.

    1. $mode = (stat($filename))[2];
    2. printf "Permissions are %04o\n", $mode & 07777;

    In scalar context, stat returns a boolean value indicating success or failure, and, if successful, sets the information associated with the special filehandle _ .

    The File::stat module provides a convenient, by-name access mechanism:

    1. use File::stat;
    2. $sb = stat($filename);
    3. printf "File is %s, size is %s, perm %04o, mtime %s\n",
    4. $filename, $sb->size, $sb->mode & 07777,
    5. scalar localtime $sb->mtime;

    You can import symbolic mode constants (S_IF* ) and functions (S_IS* ) from the Fcntl module:

    1. use Fcntl ':mode';
    2. $mode = (stat($filename))[2];
    3. $user_rwx = ($mode & S_IRWXU) >> 6;
    4. $group_read = ($mode & S_IRGRP) >> 3;
    5. $other_execute = $mode & S_IXOTH;
    6. printf "Permissions are %04o\n", S_IMODE($mode), "\n";
    7. $is_setuid = $mode & S_ISUID;
    8. $is_directory = S_ISDIR($mode);

    You could write the last two using the -u and -d operators. The commonly available S_IF* constants are

    1. # Permissions: read, write, execute, for user, group, others.
    2. S_IRWXU S_IRUSR S_IWUSR S_IXUSR
    3. S_IRWXG S_IRGRP S_IWGRP S_IXGRP
    4. S_IRWXO S_IROTH S_IWOTH S_IXOTH
    5. # Setuid/Setgid/Stickiness/SaveText.
    6. # Note that the exact meaning of these is system dependent.
    7. S_ISUID S_ISGID S_ISVTX S_ISTXT
    8. # File types. Not necessarily all are available on your system.
    9. S_IFREG S_IFDIR S_IFLNK S_IFBLK S_IFCHR S_IFIFO S_IFSOCK S_IFWHT S_ENFMT
    10. # The following are compatibility aliases for S_IRUSR, S_IWUSR, S_IXUSR.
    11. S_IREAD S_IWRITE S_IEXEC

    and the S_IF* functions are

    1. S_IMODE($mode) the part of $mode containing the permission bits
    2. and the setuid/setgid/sticky bits
    3. S_IFMT($mode) the part of $mode containing the file type
    4. which can be bit-anded with e.g. S_IFREG
    5. or with the following functions
    6. # The operators -f, -d, -l, -b, -c, -p, and -S.
    7. S_ISREG($mode) S_ISDIR($mode) S_ISLNK($mode)
    8. S_ISBLK($mode) S_ISCHR($mode) S_ISFIFO($mode) S_ISSOCK($mode)
    9. # No direct -X operator counterpart, but for the first one
    10. # the -g operator is often equivalent. The ENFMT stands for
    11. # record flocking enforcement, a platform-dependent feature.
    12. S_ISENFMT($mode) S_ISWHT($mode)

    See your native chmod(2) and stat(2) documentation for more details about the S_* constants. To get status info for a symbolic link instead of the target file behind the link, use the lstat function.

分享到:
评论

相关推荐

    redis-stat 离线安装

    标题 "redis-stat 离线安装" 涉及到的是在没有网络或者网络环境受限的情况下,如何安装和使用 `redis-stat` 这一工具。`redis-stat` 是一个用于监控 Redis 数据库性能的工具,它能提供实时的统计信息,帮助管理员...

    redis-stat 监控集成包

    3. **可视化界面**:`redis-stat` 提供了一个简单的 Web 界面,用户可以直观地查看 Redis 的实时状态和历史数据,这对于故障排查和性能优化非常有帮助。 4. **集成与扩展**:除了基本功能,`redis-stat` 还可能支持...

    fstat、stat和lstat异同

    stat系统调用系列包括了fstat、stat和lstat,它们都是用来返回“相关文件状态信息”的,三者的不同之处在于设定源文件的方式不同。

    uni-stat依赖文件

    总结来说,uni-stat是一个为uni-app提供数据埋点功能的库,它允许开发者轻松地收集和上报用户行为数据,以支持数据分析和产品优化。通过安装、配置和使用uni-stat提供的API,我们可以实现自定义事件上报以及页面的...

    redis-stat监控集成包完整版.zip

    软件介绍: 已经收集齐全的redis-stat集成包打包在一起,免去了去rubygem上...stat-0.4.12-java.gemsi-0.1.4.gemsinatra-1.3.3.gemtabularize-0.2.9.gemthin-1.5.0.gemtilt-1.3.3.gemunicode-display_width-0.1.1.gem

    Redis监控系统redis-stat离线安装

    Redis监控系统Redis-stat的离线安装是一个针对Redis数据库性能监控的重要步骤,对于系统管理员和开发者来说,能够实时了解Redis服务器的运行状态至关重要。本文将详细介绍如何在没有网络连接的情况下,通过离线方式...

    stat.xslnginx-rtmp-module-stat.xsl

    stat.xslnginx-rtmp-module-stat.xsl conf/nginx.conf 为配置文件实例 RTMP监听 1935 端口,启用live 和hls 两个application HTTP监听 8080 端口, * :8080/stat 查看stream状态 * :8080/index.html 为一个...

    JAK-STAT信号通路负反馈调节家族与类风湿性关节炎

    JAK-STAT信号通路负反馈调节家族与类风湿性关节炎,杨馨,刘旭光,类风湿性关节炎是临床常见的自身免疫性疾病,其病理过程的发生、发展都与细胞因子信号转导密切相关,而JAK-STAT通路是介导细胞因子�

    前端开源库-ml-stat

    前端开源库-ml-statml stat,用于计算数组和矩阵统计的函数

    vue-stat:vue 统计埋点插件

    vue-stat vuejs 统计埋点插件,目前可适用于友盟和百度统计 安装 npm install vue-stat --save 在页面中引用 import stat from 'vue-stat' 使用插件 Vue.use(stat, 'YOUR_SITEID') 通过 options 参数进行更多设置 ...

    echarts-stat:Apache ECharts 统计工具(孵化)

    npm install echarts-stat 否则,从下载此工具: &lt; script src =' ./dist/ecStat.js ' &gt; &lt;/ script &gt; &lt; script &gt; var result = ecStat . clustering . hierarchicalKMeans ( data , ...

    Laravel开发-laravel-stat-search-analytics

    在本文中,我们将深入探讨基于Laravel框架的`laravel-stat-search-analytics`项目,这是一个用于统计和分析搜索数据的API包装器。Laravel是PHP领域中最受欢迎的Web应用程序开发框架,以其优雅的语法和强大的功能著称...

    鼠源共表达质粒pEndo-Si-Stat3构建及鉴定

    鼠源共表达质粒pEndo-Si-Stat3构建及鉴定,李馨,李扬,[目的]:构建SiRNA-Stat3联合Endostatin共表达质粒pEndo-Si-Stat3,并检测其有效性,为后续研究所用。[方法]: 应用分子生物学技术构建共表达�

    JSON-stat:JSON-Stat Toolkit版本0

    重要通知这是JSON-stat Javascript Toolkit版本0( )的存储库。 该存储库被冻结,不再维护。 JSON-stat Javascript Toolkit版本1( )是当前的活动版本,可在新的存储库中找到: : 。JSON-stat Javascript工具包是...

    conv:JSON-stat命令行转换工具

    JSON-stat命令行转换工具 JSON-stat命令行转换工具包含用于与进行相互转换的命令行工具。 它们支持不同的JSON版本,CSV(包括 )和 。 它们建立在和。 安装 npm install -g jsonstat-conv 在“页面中有更多信息。 ...

    SE-Stat-Finder:SE-Stat-Finder听起来确实很不错,您可以查找Sector的Edge玩家并进行比赛

    SE-Stat-Finder听起来确实很不错,您可以查找Sector's Edge的球员和比赛。 使用此软件包收集的所有信息均可在公开获得 吉特 要保持最新更改,请首先克隆此仓库并用cd插入其中: git clone ...

    json-stat2qb:JSON-Stat 2 QB转换器

    JSON-Stat包括了数据集、系列、类别和值等核心元素,支持多维数据和时间序列。 **QB(Qlik Bridge)格式** QB格式是Qlik公司为与其他数据源集成而设计的一种数据格式。它允许用户将外部数据导入到Qlik环境中,如...

Global site tag (gtag.js) - Google Analytics