linux中如何取得一个文件的权限?
2017-08-03 22:07
169 查看
例:如何取得/etc/hosts文件的权限对应的数字内容,如-rw-r--r-- 为 644,要求使用命令取得644这样的数字
方法1:sed[root@ZHOUQIZHONG ~]# stat /etc/hosts | sed -nr'4s#.*\(0|/-.*##gp'
644
[root@ZHOUQIZHONG ~]#
方法2:sed 反向引用
[root@ZHOUQIZHONG tmp]# stat /etc/hosts |sed -nr '4s#.*\(0(.*)\/-.*#\1#gp'
644
[root@ZHOUQIZHONG tmp]#
方法3:awk
[root@ZHOUQIZHONG ~]# stat /etc/hosts |awk -F'[/0]' 'NR==4{print $2}'
644
[root@ZHOUQIZHONG ~]#
方法4:stat
[root@ZHOUQIZHONG ~]# stat -c%a /etc/hosts
644
[root@ZHOUQIZHONG ~]#
>>>>>>>>刚学的这些方法,方法还有很多,linux魅力无穷啊<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
相关文章推荐
- linux 下如何给一个普通用户有在指定目录下有创建文件的权限
- Linux系统下如何查看及修改文件读写权限
- Linux系统下如何查看及修改文件读写权限
- Linux系统如何查看及修改文件读写权限
- linux文件或目录权限修改后如何恢复
- Linux系统如何查看及修改文件读写权限查看文件权限的语句:
- 在Linux上,如何知道一个可执行文件是否包含调试信息呢?
- linux里的文件,如何设置为只读权限文件
- linux下如何统计一个目录下的文件个数以及代码总行数的命令
- 如何取得Win7文件的管理员权限?
- Linux 如何安装*.bin的文件 ,例如刚刚下载了一个(AdbeRdr9.4.2-1_i486linux_enu.bin)的文件
- 简析Linux中如何改变文件或目录的访问权限
- Linux系统如何查看及修改文件读写权限(ZZ)
- linux 如何显示一个文件的某几行(中间几行)
- Linux下如何查看一个文件夹下有多少文件
- Linux系统下如何查看及修改文件读写权限
- linux下如何统计一个目录下的文件个数以及代码总行数的命令
- Linux中目录文件权限如何定义?
- linux 如何显示一个文件的某几行(中间几行)
- 在linux下如何把一个lvm的文件系统减小