显示了七列信息,从左至右依次为:权限、文件数、归属用户、归属群组、文件大小、创建日期、文件名称
d :第一位表示文件类型
  d 文件夹
  - 普通文件
  l 链接
  b 块设备文件
  p 管道文件
  c 字符设备文件
  s 套接口文件

 
rwx :第2-4位表示这个文件的属主拥有的权限。r是读、w是写、x是执行
 
r-x :第5-7位表示和这个文件属主所在同一个组的用户所具有的权限
 
r-x :第8-10位表示其他用户所具有的权限

常用的linux文件权限:

444 r--r--r--
600 drw-------
644 drw-r--r--
666 drw-rw-rw-
700 drwx------
744 drwxr--r--
755 drwxr-xr-x
777 drwxrwxrwx
1、从左至右,1-3位数字代表文件所有者的权限,4-6位数字代表同组用户的权限,7-9数字代表其他用户的权限。

 一共有10位数,其中:最前面那个 - 代表的是类型

  中间那三个 rw- 代表的是所有者(user)

  然后那三个 rw- 代表的是组群(group)

  最后那三个 r-- 代表的是其他人(other)

而具体的权限是由数字来表示的,读取的权限等于4,用r表示;写入的权限等于2,用w表示;执行的权限等于1,用x表示;

2、通过4、2、1的组合,得到以下几种权限:

0(没有权限);4(读取权限);5(4+1 | 读取+执行);6(4+2 | 读取+写入);7(4+2+1 | 读取+写入+执行)

以755为例:
4-6位5等于4+1+0,r-x,同组用户具有读取、执行权限但没有写入权限;
7-9位5,同上,也是r-x,其他用户具有读取、执行权限但没有写入权限。

使用数字来进行权限管理:

r-- = 4;对应的二进制:100

-w-=2;对应的二进制: 010

--x=1;  对应的二进制:001

将对应的值相加即可进行权限管理,如:

rw-=4+2=6;

r-x=4+1=5;

rwx=4+2+1=7;

-wx=2+1=3;

3. 改变权限, chmod

权限的设定方法有两种, 分别可以使用数字或者是符号来进行权限的变更。

参数说明(cfvR):

-c : 若该档案权限确实已经更改,才显示其更改动作

-f : 若该档案权限无法被更改也不要显示错误讯息

-v : 显示权限变更的详细资料

-R : 对目前目录下的所有档案与子目录进行相同的权限变更(即以递回的方式逐个变更), 这个-R 用的还是很多的。

关于MODE:(都是同一种格式)

 `[ugoa]*([-+=]([rwxXst]*|[ugo]))+'.

说明:u 表示该档案的拥有者,g 表示与该档案的拥有者属于同一个群体(group)者,o 表示其他以外的人,a 表示这三者皆是。 
+ 表示增加权限、- 表示取消权限、= 表示唯一设定权限。 
r 表示可读取,w 表示可写入,x 表示可执行,X 表示只有当该档案是个子目录或者该档案已经被设定过为可执行。

二、更改文件所有权(chown命令详解)

看一下提示信息:

amosli@amosli-pc:~/learn/re$ chown --help
Usage: chown [OPTION]... [OWNER][:[GROUP]] FILE...
or: chown [OPTION]... --reference=RFILE FILE...
Change the owner and/or group of each FILE to OWNER and/or GROUP.
With --reference, change the owner and group of each FILE to those of RFILE. -c, --changes like verbose but report only when a change is made
--dereference affect the referent of each symbolic link (this is
the default), rather than the symbolic link itself
-h, --no-dereference affect each symbolic link instead of any referenced
file (useful only on systems that can change the
ownership of a symlink)
--from=CURRENT_OWNER:CURRENT_GROUP
change the owner and/or group of each file only if
its current owner and/or group match those specified
here. Either may be omitted, in which case a match
is not required for the omitted attribute
--no-preserve-root do not treat `/' specially (the default)
--preserve-root fail to operate recursively on `/'
-f, --silent, --quiet suppress most error messages
--reference=RFILE use RFILE's owner and group rather than
specifying OWNER:GROUP values
-R, --recursive operate on files and directories recursively
-v, --verbose output a diagnostic for every file processed The following options modify how a hierarchy is traversed when the -R
option is also specified. If more than one is specified, only the final
one takes effect. -H if a command line argument is a symbolic link
to a directory, traverse it
-L traverse every symbolic link to a directory
encountered
-P do not traverse any symbolic links (default) --help display this help and exit
--version output version information and exit Owner is unchanged if missing. Group is unchanged if missing, but changed
to login group if implied by a `:' following a symbolic OWNER.
OWNER and GROUP may be numeric as well as symbolic. Examples:
chown root /u Change the owner of /u to "root".
chown root:staff /u Likewise, but also change its group to "staff".
chown -hR root /u Change the owner of /u and subfiles to "root". Report chown bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'chown invocation'

语法格式:

chown [OPTION]... [OWNER][:[GROUP]] FILE...

chown [OPTION]... --reference=RFILE FILE...

参数说明:

 必要参数:

    -c 若该档案拥有者确实已经更改,才显示其更改动作

    -f 忽略错误信息,若该档案拥有者无法被更改也不要显示错误讯息

    -h 修复符号链接,只对于连结(link)进行变更,而非该 link 真正指向的档案

    -R 处理指定目录以及其子目录下的所有文件

    -v 显示详细的处理信息

    -deference 作用于符号链接的指向,而不是链接文件本身

  选择参数:

    --reference=<目录或文件> 把指定的目录/文件作为参考,把操作的文件/目录设置成参考文件/目录相同拥有者和群组

    --from=<当前用户:当前群组> 只有当前用户和群组跟指定的用户和群组相同时才进行改变

    --help 显示帮助信息

    --version 显示版本信息

常用格式:

chown user.group filename

实例:

1.将所有者改为root:

amosli@amosli-pc:~/learn/re$ ll #改之前
total 8
drwxrwxr-x 2 amosli amosli 4096 12月 27 00:18 ./
drwxrwxr-x 7 amosli amosli 4096 12月 26 22:32 ../
-rwxr-xr-x 1 amosli amosli 0 12月 27 00:18 a.txt*
amosli@amosli-pc:~/learn/re$ sudo su
[sudo] password for amosli:
root@amosli-pc:/home/amosli/learn/re# chown root a.txt
root@amosli-pc:/home/amosli/learn/re# ll #改之后
total 8
drwxrwxr-x 2 amosli amosli 4096 12月 27 00:18 ./

drwxrwxr-x 7 amosli amosli 4096 12月 26 22:32 ../
-rwxr-xr-x 1 root amosli 0 12月 27 00:18 a.txt*

ll的结果返回七列,分别表示如下含义:

第一栏  [文件属性]  drwxrwxr-x

第二栏  [文件数]      2

第三栏  [拥有者]       amosli

第四栏  [所有者群组] amosli

第五栏  [大小]         4096

第六栏  [建档日期]   12月 27 00:18

第七栏  [档名]        ./

2.将整个目录下的文件的所有者都改为root

改之前:

root@amosli-pc:/home/amosli/learn# ll
total 128
drwxrwxr-x 7 amosli amosli 4096 12月 26 22:32 ./
drwxr-xr-x 69 amosli amosli 4096 12月 26 23:55 ../
---------- 1 amosli amosli 3 12月 18 22:49 a1
-rw-rw-r-- 1 amosli amosli 3 12月 18 22:49 a2
-rw-rw-r-- 1 amosli amosli 3 12月 18 22:49 a3
-rw-rw-r-- 1 amosli amosli 0 12月 26 00:39 a.mp3

更之后:

root@amosli-pc:/home/amosli/learn# chown root . -R
root@amosli-pc:/home/amosli/learn# ll
total 128
drwxrwxr-x 7 root amosli 4096 12月 26 22:32 ./
drwxr-xr-x 69 amosli amosli 4096 12月 26 23:55 ../
---------- 1 root amosli 3 12月 18 22:49 a1
-rw-rw-r-- 1 root amosli 3 12月 18 22:49 a2
-rw-rw-r-- 1 root amosli 3 12月 18 22:49 a3
-rw-rw-r-- 1 root amosli 0 12月 26 00:39 a.mp3

三、chattr命令详解

使用chattr命令创建不可修改的文件

终端里,chattr命令的提示信息非常少,只给了一个语法格式:

root@amosli-pc:/home/amosli/learn/re# chattr --help
Usage: chattr [-RVf] [-+=AacDdeijsSu] [-v version] files...

常用语法格式:

sudo chattr +i a.txt
或者
chattr +i a.txt

实例:

root@amosli-pc:/home/amosli/learn/re# chattr +i a.txt
root@amosli-pc:/home/amosli/learn/re# ll
total 8
drwxrwxr-x 2 amosli amosli 4096 12月 27 01:02 ./
drwxrwxr-x 7 amosli amosli 4096 12月 26 22:32 ../
-rw-r--r-- 1 root root 0 12月 27 01:02 a.txt
root@amosli-pc:/home/amosli/learn/re# rm a.txt
rm: cannot remove `a.txt': Operation not permitted

使用chattr命令更改的权限即使是chmod命令也不能更改文件现有权限,如下:

root@amosli-pc:/home/amosli/learn/re# chmod 777 a.txt
chmod: changing permissions of `a.txt': Operation not permitted
root@amosli-pc:/home/amosli/learn/re# chmod a+rwx a.txt
chmod: changing permissions of `a.txt': Operation not permitted

但是如果文件要重新获取可写应该怎么办呢??

如下,chattr -i a.txt即可

root@amosli-pc:/home/amosli/learn/re# chattr -i a.txt
root@amosli-pc:/home/amosli/learn/re# ll
total 8
drwxrwxr-x 2 amosli amosli 4096 12月 27 01:02 ./
drwxrwxr-x 7 amosli amosli 4096 12月 26 22:32 ../
-rw-r--r-- 1 root root 0 12月 27 01:02 a.txt
root@amosli-pc:/home/amosli/learn/re# chmod a+rwx a.txt
root@amosli-pc:/home/amosli/learn/re# ll
total 8
drwxrwxr-x 2 amosli amosli 4096 12月 27 01:02 ./
drwxrwxr-x 7 amosli amosli 4096 12月 26 22:32 ../
-rwxrwxrwx 1 root root 0 12月 27 01:02 a.txt*

chmod / chown /chattr的更多相关文章

  1. 目录(cd mkdir rmdir rm pwd ls) 文件(ln touch mv rm cat more head rail) 文件权限(chmod chown chgrp) 文件通配符(* ? [])

    记住Linux目录树的结构是一个称职Linux系统管理员的必备素质! 目录漫游cd   cd - 目录显示pwd 目录管理 mkdir -p a/b/c/1 parent创建多层目录 -m 700   ...

  2. 【转】Linux中文件的可读,可写,可执行权限的解读以及chmod,chown,chgrp命令的用法

    chmod是更改文件的权限 chown是改改文件的属主与属组 chgrp只是更改文件的属组. 一.文件权限解读 如上图所示,开头的-rwxrw-r--这一字符串标识文件权限. 这个字符串有10位,可以 ...

  3. linux中权限管理命令(chmod/chown/chgrp/unmask)

    目录 chmod chown chgrp umask chmod 解释 命令名称:chmod 命令英文原意:change the permissions mode of a file 命令所在路径:/ ...

  4. 第四节 mount /who / mkdir /rmdir /rm /cp /mv /touch /cat /tac/head /tail /more /less / chmod /chown /umask /chattr /lsattr /history /echo

    ***Linux下的文件类型如下: 9 8 7 6 5 4 3 2 1 0- r w x r - x r - x 第9位表示文件类型,可以为p.d.l.s.c.b和-:p表示命名管道文件 -pipe ...

  5. chown chmod chgrp chattr chroot usermod 命令简单分析

    chown用于修改文件或目录的所属主与所属组,格式为:“chown [参数] 所属主:所属组 文件或目录名称”.[root@localtion ~]# chown root:bin test[root ...

  6. chmod/chown/chgrp/chattr

    权限组合其实就是二进制的组合 注意,用户只能修改属于自己的文件 仅管理员可以修改文件的数组和属主 chmod 三种使用方法 文件的特殊权限 SUID SGID Sticky chowm 修改文件,目录 ...

  7. LINUX 下chmod|chown|chgrp和用法和区别

    1.chgrp(转变文件所属用户组) chgrp 用户组 文件名 ###便是这个格了.若是整个目次下的都改,则加-R参数用于递归. 如:chgrp -R user smb.conf 2.chown(转 ...

  8. linux权限,所有者、所在组、其他组(其他人员),chmod,chown

    用户组 在linux中的每个用户必须属于一个组,不能独立于组外.在linux中每个文件有所有者.所在组.其它组的概念 - 所有者 - 所在组 - 其它组 - 改变用户所在的组 所有者 一般为文件的创建 ...

  9. linux笔记:权限管理命令chmod,chown,chgrp,umask

    权限对文件和目录的含义是不同的:对文件来说:读:可以查看文件内容写:可以修改文件内容执行:可以执行文件对目录来说:读:可以列出目录中的内容写:可以在目录中创建.删除文件执行:可以进入目录 能够更改文件 ...

随机推荐

  1. js获取当前网页header头部信息

    思路,通过ajax重新请求当前页面,用getAllResponseHeaders方法获取: var req = new XMLHttpRequest();req.open('GET', documen ...

  2. 01背包 hdu1864

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1864 注意事项: 在这里所有输入的价格都是两位小数(题目没说,看论坛才知道的). 这里单项价格不能超过 ...

  3. Apache+PHP+MySQL环境搭建

    准备安装包:Apache: apache_2.2.11-win32.msi (http://pan.baidu.com/s/1nvdiNcH)PHP: php-5.2.5-Win32.zip (htt ...

  4. Sigar--系统性能监测

    Sigar(System Information Gatherer And Reporter),是一个开源的工具,提供了跨平台的系统信息收集的API.可以收集的信息包括: 1, CPU信息,包括基本信 ...

  5. [转]Docker到底是什么?为什么它这么火?

    如果你是数据中心或云计算IT圈子的人,这一年多来应该一直在听到普通的容器.尤其是Docker,关于它们的新闻从未间断过.Docker1.0在今年6月发布后,声势更是达到了前所未有的程度. 动静之所以这 ...

  6. zabbix基础使用(以思科交换机为例)

    1.创建host group --以方便添加告警和给host分组 一般先创建一个Group-Net,然后根据地点创建.命名,如Group-Net-BeiJing 2.创建Template 1.创建Di ...

  7. 解决com.microsoft.sqlserver.jdbc.SQLServerException: 该连接已关闭

    com.microsoft.sqlserver.jdbc.SQLServerException: 该连接已关闭. at com.microsoft.sqlserver.jdbc.SQLServerEx ...

  8. DBCO

    实现SAP连接外部数据库 也可用SM30维护DBCON的内容 SAP提供了对原生sql的操作,主要有以下几个类组成: CL_SQL_STATEMENT - Execution of SQL State ...

  9. docker-ce-17.09 容器创建,运行,进入,删除,导入/导出

    docker容器是镜像运行的一个运行实例,带有额外的可写文件层. 一.创建容器 > docker create -it centos:latest create命令新建的容器处于停止状态,可以使 ...

  10. asp.net core webapi iis jquery No 'Access-Control-Allow-Origin' header is present on访问跨域问题

    我的解决方案是:设置特定method允许所有请求源访问,具体看业务需求 第一步:starup文件下ConfigureServices中增加如下配置 //跨域//设置了允许所有来源 services.A ...