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) ...
随机推荐
- ssh 远程执行命令
SSH 是 Linux 下进行远程连接的基本工具,但是如果仅仅用它来登录那可是太浪费啦!SSH 命令可是完成远程操作的神器啊,借助它我们可以把很多的远程操作自动化掉!下面就对 SSH 的远程操作功能进 ...
- 2018-2019-2 网络对抗技术 20165324 Exp4:恶意代码分析
2018-2019-2 网络对抗技术 20165324 网络对抗技术 Exp4:恶意代码分析 课下实验: 实践目标 是监控你自己系统的运行状态,看有没有可疑的程序在运行. 是分析一个恶意软件,就分析E ...
- iOS UI基础-4.0应用程序管理
功能与界面 功能分析: 以九宫格的形式展示应用信息 点击下载按钮后,做出相应的操作 步骤分析: 加载应用信息 根据应用的个数创建对应的view 监听下载按钮点击 整个应用界面: 程序实现 思路 UI布 ...
- Must be between v0 and v15, inclusive解决办法
invoke-static 改为invoke-static/range
- react native 示例代码
https://react.rocks/tag/ReactNative?show=60 https://github.com/ReactNativeNews/React-Native-Apps
- js时钟
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 004-ubuntu安装配置SSH服务
一.ssh安装. 1.# sudo apt-get -y install openssh-server. 2.在/etc/ssh/sshd_config文件中添加一句:PermitRootLogin ...
- cf249D
这题说的是给了一个n*m的网格,然后每个格子的点事黑色的或者是白色的然后每个点如图所示 然后只能用白点和图中给出的边建立三角形然后询问三角形的个数有多少个,这样说每个三角形的边必须是图中有的边, ...
- AVPlayerLayer
AVPlayerLayer 最后一个图层类型是AVPlayerLayer.尽管它不是Core Animation框架的一部分(AV前缀看上去像),AVPlayerLayer是有别的框架(AVFound ...
- 复制控件出错--提示XX控件不存在
有时候比较喜欢复制粘贴,但是结果就是,经常出现XX控件找不到,或者不存在之类的话~~ 错误如下: 在相当郁闷的时候,尝试了一种很土土的方法,就是直接新建一个同名新页面,把前台和后台的代码复制进去~~ ...