开发者学堂课程【Linux 操作系统实战:Linux 文件基本属性】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/699/detail/12285
Linux 文件基本属性
内容介绍:
一、列出目录及文件信息命令
二、目录及文件基本属性
三、目录及文件基本属性
一、列出目录及文件信息命令
Is、ll(是 Is 的特殊用法)
1.用途:
Linux Is 命令用于显示指定工作目录下之内容(列出目前工作目录所含之文件及子目录)。
2.语法:
Is [-alrtAFR] [name..]
3.参数:
-a 显示所有文件及目录(Is内定将文件名或目录名称开头为”."的视为隐藏档,不会列出)
-1除文件名称外,亦将文件型态、权限、拥有者、文件大小等资讯详细列出,也可以用11命令表示,如下:Is-l=Il
-r 将文件以相反次序显示(原定依英文字母次序)
-t 将文件依建立时间之先后次序列出
-A 同-a,但不列出”.”(目前目录)及..”(父目录)
-F 在列出的文件名称后加一符号;例如可执行档则加“**,目录则加“/”
-R 若目录下有文件,则以下之文件亦皆依序列出
使用客户端进行展示 Is 命令怎样使用:
链接端口号,重新连接,输入用户名和密码,摁下回车。
(1)[root@AliECS ~]# 11
total 0
drwxr-xr--2root root 6 May 28 17:38 test
-xW-F--r--1root root 0 May 2817:42 test.txt
(2)[root@AliECS ~]# 1s -1
total 0
drwxr-xr--2root root6 May 2817:38 test
-rw-r--r-- 1 root root 0 May 28 17:42 test.txt
(3)[root@AliECS~]# Is -a
.bash logout .cache .pip .tcshrc .viminfo
.bash profile .config .pydistutils.cfg test
.bash history .bashrc .cshrc .ssh test.txt
(4)[root@AliECS ~]#ls -tl
total 0
-rw-r--r--1 root root 0 May 28 17:42 test.txt
drwxr-xr-- 2rootroot 6 May 28 17:38 test
(5)[root@AliECS~]# 1s -1
total 0
drwxr-xr--2root root 6May28 17:38 test
-rw-r--r-- 1 rootroot 0May 28 17:42 test.txt
以上是常见的命令。
下面是比较复杂的命令。
示例:Is-ltr s*、Is-IR/bin
[root@iZwz97rb6e0a611ynu7kftZ ~]# 11
total 335056
-rw-r--r--.1 root root 251 Jan 27 2017 my.cnf-bak
drwxr-xr-x13 root root 4096 May 15 22:59mysql-5.6.48-1inux-glibc2.12-x86 64
-IW-I--r-- 1 root root 343082156 Mar 9 23:37 mysql-5.6.48-1inux-glibc2.12-x86 64.tar.gz
二、目录及文件基本属性
文件类型-表示文件,看下test目录,是一个子目录,表示目录的文件,相关链接是分成三段来介绍权限。
1.属主权限,表示所有的权限
123位表示属主权限,如:rwx 表示读、写、执行权限。
2.属组权限。
456位表示属组权限,如:r-x 表示读、执行权限。
3.其他用户权限
789位表示其他用户权限,如:r-x 表示读、执行权限。
字母表示和数字表示的对应关系:
r 表示4
w 表示2
x 表示1
-表示0
三、更改目录及文件属性命令
有了相关权限后,使用命令的操作如下;
推荐使用以下方法:
1.chmod
当值为 rwx,rw-wx 时,对应的数字值为“763”
操作如下:
先输入用户名和密码。
[root@AliEcs -] #II
total 0
drwxr-xr-- 2 root root 6 May 2817:38test
-rw-r--r-- 1 root root 0 May 28 17:42test.txt
[root@AliECS~]# chmod 654 test
[root@AliECS~]# 11
total 0
drw-r-xr-- 2 root root 6 May 28 17:38 test
-rw-r--r-- 1 root root 0 May 28
[root@AliECS ~]# chmod 655 test
[root@AliECS ~]# 11
total 0
drw-r-xr-X2 root root 6 May 28 17:38
test-rw-r--r-- 1 root root 0 May 28 17:42 test.txt
[root@AliECS ~]# chmod u+x test
[root@AliECS~]# 11
total 0
drwxr-xr-x 2 root root 6 May 28 17:38 test
-rW-r--r-- 1 root root 0 May 28 17:42 test.txt
[root@AliECS~]# chmod o+w test
[root@AliECS~]# II
total 0
drwxr-xrwX2 root root6 May 28 17:38 test
-xW-r--r-- 1 root root 0 May 28 17:42test.txt
[root@AliECS~]#
以上就是相关的全部操作。有了目录及文件属性,也可以采用递归的用法进行使用。
2.chown
可以改变文件的拥有者和所属者
格式:chown-R rootroot file
目录里有子文件。
操作如下:
[root@ALiY ~]# 11
total 0
drwxr-xr-x 2 root root 6 Jun 7 17:50 test [root@ALiY ~]# chown -R ken:root test [root@ALiY ~]# 11
total 0
drwxr-xr-x 2 ken root6 Jun 7 17:50 test
[root@ALiY ~]#
3.umask
当默认 umask 值为0002时,更改为 umask 022新建文件或目录时,在原来默认权限基础上,所有者权限不变、所在组减去写权限、其他用户也减去写权限。
指定在建立文件时预设的权限掩码 umask:
用途:umask 可用来设定[权限掩码]。[权限掩码]是由3个八进制的数字所组成,将现有的存取权限减掉权限掩码后,即可产生建立文件时预设的权限。
语法:umask-S[权限掩码]
参数说明:
-S 以文字的方式来表示权限掩码
示例:
使用指令“umask”查看当前权限掩码,则输入下面的命令:umask#获取当前权限掩码
使用指令"mkdir”创建一个目录,并使用指令"Is"获取该目录的详细信息,输入命令如下:
$mkdir test1#创建目录
$Is -d -I test1/#显示目录的详细信息
执行上面的命令后,将显示新创建目录的详细信息,如下所示:
drwxr-xr-x 2root root4096 2011-9-19 21:46 test1/
注意:在上面的输出信息中,"drwxr-xr-x"="777-022=755”。
操作如下:
[root@ALiY ~]# II
total 0
drwxr-xr-x 2 root root 6 Jun 7 17:50 test
[root@ALiY ~]#chown -R ken:root test
[root@ALiY ~]# II
total 0
drwxr-xr-x 2 ken root6 Jun 7 17:50 test
[root@ALiY ~]# umask
0022
[root@ALiY ~]# mkdir test1
[root@ALiY ~]# 11
total 0
drwxr-xr-x 2 ken root 6 Jun 7 17:50 test
drwxr-xr-x 2 root root 6 Jun 7 18:12 test1
[root@ALiY ~]# umask 222
[root@ALiY ~]# mkdir test2
[root@ALiY ~]# II
total 0
drwxr-xr-x 2 ken root6 Jun 7 17:50test
drwxr-xr-x 2 root root6 Jun 7 18:12test1
dr-xr-xr-x 2 root root 6 Jun 7 18:13 test2
[root@ALiY ~]#