linux设置文件命令,linux下设置文件属性的命令

对普通用户来说,一个文件的属性一般只指可读、可写、可执行等权限。使用命令ls -l也很容易来查看某个文件或文件夹的权限。

zhangyu@ubuntu-systemplatfor:~/test$ ls -l

total 16

-rwxrwxr-x 1 zhangyu zhangyu 8438 33 09:29 test

drwxrwxr-x 2 zhangyu zhangyu 4096 31 17:31 testdir

对于第3/4行中的第一列就是表示该文件的权限,相信很多人都熟悉。这里再�嗦一下0818b9ca8b590ca3270a3433284dd417.png。数一数它,总共有十位标记,具体说明看下表。

本用户

用户所在用户组

其他用户组

1

2

3

4

5

6

7

8

9

10

文件/目录

读权限

写权限

执行权限

读权限

写权限

执行权限

读权限

写权限

执行权限

‘d’表示目录

‘l’符号链接

‘-’表示无此权限,‘r’可读,‘w’可写,‘x’可执行

我们可以使用chmod命令来修改文件的权限。

zhangyu@ubuntu-systemplatfor:~/test$ chmod -x test

zhangyu@ubuntu-systemplatfor:~/test$ ls -l test

-rw-rw-r-- 1 zhangyu zhangyu 8438 33 09:29 test

‘-x’以为清除文件的可执行权限,同样‘+x’可以增加其可执行权限。同理也存在‘+r’、‘+w’、‘-r’等等。另外还有一种方法,按照掩码来修改权限。

zhangyu@ubuntu-systemplatfor:~/test$ chmod 555 test

zhangyu@ubuntu-systemplatfor:~/test$ ls -l test

-r-xr-xr-x 1 zhangyu zhangyu 8438 33 09:29 test

与上表中对应,第一个5对应本用户的读写执行权限的掩码,第二个5对应本用户组的读写权限的掩码,第三个5就对应其他用户组了。用二进制表示5为101,恰好对应三种权限,也就是说掩码最大只能设置为777,即111 111 111。

对于超级用户,还有一组命令lsattr/chattr来查看和修改文件的属性,这些属性对一般用户是不可用的,若修改它们则需要超级用户权限。标志位的设置使用‘+’和‘-’来增加或清除。

zhangyu@ubuntu-systemplatfor:~/test$ lsattr test

-------------e- test

zhangyu@ubuntu-systemplatfor:~/test$ chattr +i test

chattr: 不允许的操作 while setting flags on test

zhangyu@ubuntu-systemplatfor:~/test$ sudo chattr +i test

[sudo] password for zhangyu:

zhangyu@ubuntu-systemplatfor:~/test$ lsattr test

----i--------e- test

对于每个flag所代表的意思可以使用man命令来查看,也可以百度和google。在不同的linux系统中,参数可能存在差别(在BSD系统中则是chflags命令)。

就我的机器(ubuntu 64bit)中,使用man chattr可以看到:

NAME

chattr - change file attributes on a Linux file system

SYNOPSIS

chattr [ -RVf ] [ -v version ] [ mode ] files...

DESCRIPTION

chattr changes the file attributes on a Linux file system.

The format of a symbolic mode is +-=[acdeijstuADST].

The operator `+' causes the selected attributes to be added to the existing attributes of the files;

`-' causes them to be removed; and `=' causes them to be the only attributes that the files have.

The letters `acdeijstuADST' select the new attributes for the files:

append only (a), compressed (c), no dump (d), extent format (e), immutable (i), data journalling (j),

secure deletion (s), no tail-merging (t), undeletable (u), no atime updates (A),

synchronous directory updates (D), synchronous updates (S), and top of directory hierarchy (T).

The following attributes are read-only, and may be listed by lsattr(1) but not modified by chattr:

huge file (h), compression error (E), indexed directory (I),compression raw access (X), and compressed dirty file (Z).

后面还有更详细的介绍,就没有全部截取出来。

一般常用的标记为:(a)即append,设定该参数后,只能向文件中添加数据,而不能删除;(i)i:设定文件不能被删除、改名、设定链接关系,同时不能写入或新增内容。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值