stat用法:获取文件对应权限的数字
题目:文件属性为-rw-r--r-- 对应权限为644,如何使用命令获取权限对应的数字??
举例如下:
[linuxidc@localhost ~]$ ll -l
-rw-r--r-- 1 linuxidc wheel 38 Oct 12 16:29 1.txt
使用stat命令可以查看
[linuxidc@localhost ~]$ stat 1.txt
File: `1.txt'
Size: 38 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 390954 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 503/ linuxidc) Gid: ( 10/ wheel)
Access: 2015-10-12 16:29:34.674990005 +0800
Modify: 2015-10-12 16:29:32.248990536 +0800
Change: 2015-10-12 16:29:32.248990536 +0800
取出对应的数字则需要使用正则sed awk 或cut ,head,tail命令;
方法1:使用正则或命令取
head,tail,cut
[linuxidc@localhost ~]$ stat 1.txt |head -n4|tail -n1|cut -d "/" -f1|cut -d "(" -f2
0644
sed,cut
[linuxidc@localhost ~]$ stat 1.txt |sed -n '4p'|cut -d "/" -f1|cut -d "(" -f2
0644
sed,awk
[linuxidc@localhost ~]$ stat 1.txt |sed -n '4p'|awk -F"/" '{print $1}'|awk -F"(" '{print $2}'
0644
方法2:stat -c 命令
[linuxidc@localhost ~]$ stat -c %a 1.txt
644
注意:如何想到法二的思考过程,比答题更重要。当命令结果包含我们需要的内容的时候,我们要想到是否有具体的参数能够一步达到我们需要的结果。
man stat 查看帮助
-c --format=FORMAT
use the specified FORMAT instead of the default; output a new line after each use of FORMAT
使用特殊格式代替默认输出;
常用的参数有如下:
%a Access rights in octal 8进制显示访问权限,0644
%A Access rights in human readable form 以人类可读的形式输出,
%F File type 文件的类型
%g Group ID of owner 所属组gid的号码
%G Group name of owner 所属组的名称
%h Number of hard links 硬连接的数量
%i Inode number inode的值
%n File name 文件名
%o I/O block size IO块大小
%s Total size, in bytes 文件的总大小,字节显示;
%u User ID of owner 所属主的uid号码
%U User name of owner 所属主的名称
%x Time of last access 最后访问的时间
%X Time of last access as seconds since Epoch 最后访问时间的时间戳
%y Time of last modification 最后修改的时间
%Y Time of last modification as seconds since Epoch 最后修改时间的时间戳
%z Time of last change 最后更改的时间
%Z Time of last change as seconds since Epoch 最后更改的时间的时间戳
使用参数结果如下:
[linuxidc@localhost ~]$ ls -l 1.txt
-rw-r--r-- 1 linuxidc wheel 38 Oct 12 16:29 1.txt
[linuxidc@localhost ~]$ stat -c %a 1.txt
644
[linuxidc@localhost ~]$ stat -c %A 1.txt
-rw-r--r--
[linuxidc@localhost ~]$ stat -c %b 1.txt
8
[linuxidc@localhost ~]$ stat -c %B 1.txt
512
[linuxidc@localhost ~]$ stat -c %d 1.txt
64768
[linuxidc@localhost ~]$ stat -c %F 1.txt
regular file
[linuxidc@localhost ~]$ stat -c %g 1.txt
10
[linuxidc@localhost ~]$ stat -c %G 1.txt
wheel
[linuxidc@localhost ~]$ stat -c %u 1.txt
503
[linuxidc@localhost ~]$ stat -c %U 1.txt
linuxidc
[baby@localhost ~]$ stat -c %h 1.txt
1
[linuxidc@localhost ~]$ stat -c %i 1.txt
390954
[linuxidc@localhost ~]$ stat -c %n 1.txt
1.txt
[linuxidc@localhost ~]$ stat -c %o 1.txt
4096
[linuxidc@localhost ~]$ stat -c %s 1.txt
38
stat用法:获取文件对应权限的数字的更多相关文章
- seek和tell的用法--获取文件内容大小(字节)
/*获取文件中存取的数据内容的大小(字节数) ellg() 和 tellp() 这两个成员函数不用传入参数,返回pos_type 类型的值(根据ANSI-C++ 标准) ,就是一个整数,代表当前get ...
- dirname的用法:获取文件的父级目录路径
命令:dirname 获取文件的路径(到父级目录)用法:dirname file_name [root@bogon opt]# a=$(dirname /mnt/a/b/c/d/a.sh) [root ...
- 获取文件的缩略图Thumbnail和通过 AQS - Advanced Query Syntax 搜索本地文件
演示如何获取文件的缩略图 FileSystem/ThumbnailAccess.xaml <Page x:Class="XamlDemo.FileSystem.ThumbnailAcc ...
- PHP获取文件扩展名的多种方法
PHP获取文件扩展名的N种方法. 第1种方法: function get_extension($file) { substr(strrchr($file, '.'), 1): } 第2种方法: fun ...
- ASP php获取文件URL地址等方法
$_SERVER["HTTP_REFERER"] rss中可用 echo next(explode("=", $_SERVER["QUERY_STRI ...
- PHP获取文件的绝对路径
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 ===========PH ...
- 【apache tika】apache tika获取文件内容(与FileUtils的对比)
Tika支持多种功能: 文档类型检测 内容提取 元数据提取 语言检测 重要特点: 统一解析器接口:Tika封装在一个单一的解析器接口的第三方解析器库.由于这个特征,用户逸出从选择合适的解析器库的负担, ...
- JAVA 获取文件的MD5值大小以及常见的工具类
/** * 获取文件的MD5值大小 * * @param file * 文件对象 * @return */ public static String getMD5(File file) { FileI ...
- node 的fs.state 获取文件信息
1. fs.stat()可以获取文件的信息,用法如下: const fs = require('fs'); fs.stat('./book.js',(err,stats)=>{ if(err) ...
随机推荐
- C++(STL)&&树-堆结构练习——合并果子之哈夫曼树
题目题解:http://blog.csdn.net/xu12110501127/article/details/9199335 有关博客:http://www.360doc.com/content/1 ...
- Choose the best route(迪杰斯特拉)
通过做这题,发现了自己的问题很大,做题不是贴代码,而是要了解思想:这题考的是有一个起点的集合,求起点集合到一个终点的最短距离, 本来想用Floy的但一看map[1000][1000]超时,有向图,逆序 ...
- BGD-py实现学习【1】[转载]
转自:https://github.com/icrtiou/Coursera-ML-AndrewNg 1.源码-对数据读取 import numpy as np import pandas as pd ...
- 从Maven仓库中导出jar包
从Maven仓库中导出jar包:进入工程pom.xml 所在的目录下,输入以下命令:mvn dependency:copy-dependencies -DoutputDirectory=lib更简单的 ...
- Servlet—生命周期
首次访问 重复访问 换浏览器访问(说明在一次项目运行期间,servlet实例只会创建一个)
- hihocoder博弈游戏·Nim游戏·三
在这一次游戏中Alice和Bob决定在原来的Nim游戏上增加一条规则:每一次行动时,不仅可以选择一堆取走任意数量的石子(至少取1颗,至多取出这一堆剩下的所有石子),还可以选择将一堆石子分成两堆石子,但 ...
- Intro to Python for Data Science Learning 3 - functions
Functions from:https://campus.datacamp.com/courses/intro-to-python-for-data-science/chapter-3-functi ...
- 20155222 2016-2017-2 《Java程序设计》第8周学习总结
20155222 2016-2017-2 <Java程序设计>第8周学习总结 教材学习内容总结 Java NIO(New IO)是一个可以替代标准Java IO API的IO API(从J ...
- Python: 在序列上执行聚集函数(比如sum() , min() , max() )
在序列上执行聚集函数(比如sum() , min() , max() ) eg1: >>>nums = [1, 2, 3, 4, 5]>>>s = sum(x * ...
- Oracle 性能调优
在 oracle 中效率排行, 表连接>exist>not exist>in>no in 并且使用in 查询 会有查询条件数量不能超过1000 的限制: 简单提高效率可以使用 ...