Linux常用命令-文件属性

文件属性会覆盖权限

1、lsattr 命令

1.1、功能:查看文件属性
1.2 用法:
    lsattr 文件

2、chattr命令

2.1、功能:修改文件属性
2.2、用法:
    chattr [选项] 文件
    常用选项:
        a : 只能追加模式写文件,适合日志文件
        i :文件不能改变,适合不可修改的文件
        + :添加属性
        - :删除属性
        = :覆盖属性       

3、实例

        ##创建文件
        [root@centos6 home]# touch test1.txt test2.txt
        [root@centos6 home]# 
        [root@centos6 home]# lsattr test*
        -------------e- test1.txt
        -------------e- test2.txt
        [root@centos6 home]# 
        ##给文件添加a属性
        [root@centos6 home]# chattr +a test1.txt 
        ##覆盖写文件,不允许
        [root@centos6 home]# echo aaa > test1.txt
        -bash: test1.txt: 不允许的操作
        [root@centos6 home]# 
        ##追加写文件,成功
        [root@centos6 home]# echo aaa >> test1.txt
        [root@centos6 home]# cat test1.txt
        aaa
        [root@centos6 home]# echo bbb >> test1.txt
        [root@centos6 home]# cat test1.txt
        aaa
        bbb
        [root@centos6 home]# 
        [root@centos6 home]# id
        uid=0(root) gid=0(root)=0(root) 环境=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
        ##删除文件,不允许
        [root@centos6 home]# rm -f test1.txt
        rm: 无法删除"test1.txt": 不允许的操作
        [root@centos6 home]# 
        ##给文件添加i属性
        [root@centos6 home]# chattr +i test2.txt
        [root@centos6 home]# lsattr test2.txt
        ----i--------e- test2.txt
        [root@centos6 home]# 
        ##覆盖写文件,失败
        [root@centos6 home]# echo aaa > test2.txt
        -bash: test2.txt: 权限不够
        ##追加写文件,也失败
        [root@centos6 home]# echo bbb >> test2.txt
        -bash: test2.txt: 权限不够
        [root@centos6 home]# 
        ##删除文件,失败
        [root@centos6 home]# rm -f test2.txt
        rm: 无法删除"test2.txt": 不允许的操作
        [root@centos6 home]#
        ##只能查看文件
        [root@centos6 home]# cat test2.txt

4、stat命令

4.1、功能:显示文件状态
4.2、用法:
    stat 文件

    实例:
        [root@centos6 ~]# stat date.txt
          File: "date.txt"
          Size: 43        	Blocks: 8          IO Block: 4096   普通文件
        Device: 802h/2050d	Inode: 4157        Links: 1
        Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
        Access: 2019-08-14 16:57:37.538988268 +0800
        Modify: 2019-08-14 16:57:31.584987349 +0800
        Change: 2019-08-14 16:57:31.584987349 +0800    
        [root@centos6 ~]# ll date.txt
        -rw-r--r--. 1 root root 43 8月  14 16:57 date.txt

5、file 命令

5.1、功能:确定文件类型,可以查看文本文件字符编码
5.2、用法:
    Usage: file [OPTION...] [FILE...]
    常用参数:
      -z : 尝试查看压缩文件
      -i : 输出MIME类型字符串(-MIME类型和--mime编码)
    实例:
       [root@centos6 ~]# file  file1.txt
       file1.txt: UTF-8 Unicode text
       [root@centos6 ~]# file -i file1.txt
       file1.txt: text/plain; charset=utf-8

       [root@centos6 ~]# file -z file2.txt.gz 
        file2.txt.gz: ASCII text (gzip compressed data, was "file2.txt", from Unix, last modified: Thu Nov 21 14:19:33 2019)
        [root@centos6 ~]# file -i file2.txt.gz 
        file2.txt.gz: application/x-gzip; charset=binary
        [root@centos6 ~]# file /dev/null
        /dev/null: character special
        [root@centos6 ~]# 
        [root@centos6 ~]# file /dev/sda1
        /dev/sda1: block special

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值