What is a file? All files are actually a string of character streams, but when using appropriate parsing methods, effective information can be obtained. In order to facilitate file operations, people have given files different types according to different file parsing methods, and marked them for people to see in the following way. Today, when I was checking the properties of the /dev/fuse file, I saw the crw_ permission bit and was confused for a moment: [root@localhost ~]# ll /dev/fuse crw-rw-rw-. 1 root root 10, 229 Sep 20 11:12 /dev/fuse A note here is that the relevant answers come from the Internet. In Linux, c represents character device file, b represents block device file, l represents symbolic link file, r represents readable permission, and w represents writable permission. Interpretation of linux file attributes: File Type: -: Ordinary file (f) Let's look at the file types in Linux (1) Regular file ('-', regular file) Divided into: binary files and text files Binary files are for machines to see, such as .bin, .elf files Text files: For human viewing, usually in ASCII encoding, need to be parsed using ASCII encoding, for example: .txt, .c files. (2) Folder file ('d', directory file) A special file, special in that it needs to be opened using its library function. (3) Link file ('l', link file) Here is the soft link file. Note: The difference between soft link files and hard link files. The soft link file is an independent file in itself and has its own inode. A hard link file is not an independent file. It shares the same inode with the linked file. (4) Pipeline file ('p', piple file) Used for process communication. (5) Socket file ('s', socket file) For network use. (6) Character device file ('c', character file) It is a virtual file because it does not exist on the hard disk and is created by fs. Cannot read or write directly, must use API. (7) Block device file ('b', block file) It is also a virtual file, created for fd, and needs to be read and written using the API. 3. How to get the properties of a file? (1) Using the stat command in the shell (2) Using the stat API in the program 4. File permissions (1) How to obtain file permissions? Using the stat API in the program, you can get the st_mode element. st_mode is a bit-based record of content, so you only need to & the corresponding bit. Linux provides the corresponding macro, which can be used. (2) How to determine whether a program has permission to access a file? First, the program's file permissions are determined by the user who executes the program. If the user has permissions, the program has them. If the user does not, the program does not have them. Secondly, the program determines whether it has permission to use the access API. Finally, an excellent program must first determine the permissions for the files being operated at the beginning of execution. If the user does not have permissions, the user needs to be reminded. (3) How to modify permissions? There is a chmod command in the shell, and there is also a chmod API, so you can use this API. (4) How are the permissions for newly created files determined? Linux has something similar to a variable called umask, and the permissions of new files are determined by umask. The umask can be changed in the shell. Summarize The above is what I introduced to you about the crw, brw, lrw and other file attributes in Linux. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: An example of refactoring a jigsaw puzzle game using vue3
>>: Detailed process of decompressing and installing mysql5.7.17 zip
Drag the mouse to take a screenshot of the page (...
Hexadecimal code table of various colors [Part 1] ...
This article uses examples to describe how to cre...
Project Background Recently, there is a project w...
Table of contents 1. Back up the old MySQL5.7 dat...
Table of contents Preface 1. Configure intranet D...
Today I'd like to introduce a countdown made ...
Table of contents Preface 1. Less 2. Import your ...
drop table Drop directly deletes table informatio...
Step 1. Enable MySQL slow query Method 1: Modify ...
Brotli is a new data format that can provide a co...
This article analyzes the process of shutting dow...
Table of contents Vue3 encapsulation message prom...
Nginx can use its reverse proxy function to imple...
Two ways to enable proxy React does not have enca...