day6-Linux file and directory attributes and permissions (ob-03)-1

1. The attributes and permissions of Linux files and directories -001

Overview of file attributes

ls -lhi

Insert picture description here
Insert picture description here
Text explanation: the
first column: inode index node; the second column: file type and permissions; the
third column: the number of hard links; the fourth column: the user (group) to which the file or directory belongs; the
fifth column: the file or directory The group to which the user belongs; the sixth column: the size of the file or directory; the
seventh, eighth, and ninth columns: the modification time of
the file or the directory; the tenth column: the actual file name or directory name

stat指令 (Display file or file system status.)

Insert picture description here

Index node inode

Insert picture description here
For example, for a book, the storage device or partition is equivalent to the book, the block is equivalent to each page in the book, and the inode is equivalent to the table of contents in the front of the book. A book has a lot of content. If you want to find a certain part of For content, we can check the catalog first, through the catalog we can find the content we want to see more quickly.

ls -li test.txt #查看文件或目录的inode值
inode值相同的文件为硬链接文件

Hard link:

In the Linux system, the real condition for deleting a file (in fact, a directory is also a file) is that all hard-linked files related to it are deleted. The hard link is equivalent to another entry of the file.

ln Syntax for creating a hard link to a file:

ln 源文件 目标文件 #注意目标文件不需要提前创建
ln oldboy oldboy_hard_link

Insert picture description here
It can be seen that when oldboy did not create the hard link file oldboy_hard_link, the number of links was 1 (that is, the value after rWXr-xr-x). After the hard link oldboy_hard_link was created, this value became 2. In other words, every time we create a new hard link file for oldboy, the number of hard links will increase by 1.

For files with the same inode value, their relationship can be regarded as a hard link relationship. When we modify the content of one of the files, the content of the files that are hard-linked to each other will also change. If we delete a file that is hard-linked to each other, the other hard-linked files will not be affected, even if the file data is still there (when the number of file hard links is 0, the data occupied space will be released and reclaimed). If we delete the oldboy file, we can still see the content of oldboy_hard_link, and the oldboy_hard_link still exists.

Note: hard links cannot be created for directories, only files can create hard links

Soft connection:

(Symbolic Link) soft link. The soft link file is similar to the shortcut in the Windows system. It is actually a special file. In a symbolic link, the file is actually a text file, and the soft link contains the location information of another file. The source file entity can be located through this "shortcut".
Insert picture description here

软连接语法:
ln -s 源文件或目录 目标文件或目录

Insert picture description here
Insert picture description here
Note : When we modify the content of the linked file, it means that we are modifying the content of the original file. At this time, the attributes of the original file will also change, but the attributes of the soft link file will not change. If we delete the original file, there will only be an invalid file name in the linked file. Because the original file is lost, the soft link file will no longer exist. This is different from hard links;

2. Attributes and permissions of Linux files and directories -002

Permissions in Linux files

Insert picture description here
Description of read, write, and execute permissions for linux ordinary files :

可读r:表示具有读取阅读文件内容的权限;
可写w、表示具有新增、修改文件内容的权限;(特别提示:删除或修改的权限受父目录的权限控制)﹔
可执行x:表示具有执行文件的权限。

Description of read, write, and execute permissions of linux directory :

进入目录的权限x
浏览目录的权限r
修改目录内文件的权限w

read-r Read permission
For files (such as oldboy), it means that it has the permission to read the content of the file;
for directories (such as /etiantian), it means that it has the permission to browse the directory (note: it is different from the permission to enter the directory) .

Insert picture description here

Pay special attention;
when deleting or moving a file or directory, it is only related to the permissions of the upper-level directory where the file and the directory are located, and has nothing to do with the attributes of the file itself.
For files: writing a file is to modify the file, not to delete the file, so writing a file is related to the properties of the file itself.
(Beat the dog to see the owner)
Insert picture description here
Insert picture description here
Insert picture description here

Change the permission attribute command chmod

#r-4 w-2 x-1
chmod  644 test.txt
如果改变的仅仅是打开目录的权限﹐使用chmod命令时不用加任何参数。
如果想把目录以下的所有文件或子目录也同时改变,需要使用-R参数;

Insert picture description here
Insert picture description here

Command umask assigned by default permissions (understand)

Insert picture description here

[root@web02 shellDir]# umask
0022

Third, the attributes and permissions of Linux files and directories -003

Insert picture description here
Insert picture description here
END

Guess you like

Origin blog.csdn.net/Nightwish5/article/details/113719617