What are the file attributes of crw, brw, lrw, etc. in Linux?

What are the file attributes of crw, brw, lrw, etc. in Linux?

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)
d: directory file
b: block device file (block)
c: character device file (character)
l: symbolic link file
p: command pipeline file (pipe)
s: socket file (socket)
File permissions: 9 bits, each group of 3 bits, each group: rwx (read, write, execute), when the group does not have a certain permission, use - instead.
The first group is: the file owner's permissions. The file owner can read and write but cannot execute.
The second group is: permissions for the same group The third group is: permissions for other groups not in this group

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:
  • How to parse the attribute interface of adding file system in Linux or Android
  • Python modifies the permissions of files (folders) in Linux
  • Linux shell - Example of how to test file system attributes by identification
  • Detailed examples of viewing file attributes in Linux (ls, lsattr, file, stat)
  • A brief discussion on the linux rwxrwxrwt folder attributes
  • Summary of Linux file basic attributes knowledge points

<<:  An example of refactoring a jigsaw puzzle game using vue3

>>:  Detailed process of decompressing and installing mysql5.7.17 zip

Recommend

HTML table tag tutorial (33): cell vertical alignment attribute VALIGN

In the vertical direction, you can set the cell a...

Detailed explanation of HTML basics (Part 2)

1. List The list ul container is loaded with a fo...

Nginx domain forwarding usage scenario code example

Scenario 1: Due to server restrictions, only one ...

Detailed example of Linux all-round system monitoring tool dstat

All-round system monitoring tool dstat dstat is a...

Embed codes for several older players

The players we see on the web pages are nothing m...

How to modify the ssh port number in Centos8 environment

Table of contents Preface start Preface The defau...

How to solve the problem of margin overlap

1. First, you need to know what will trigger the v...

MySQL uses SQL statements to modify table names

In MySQL, you can use the SQL statement rename ta...

CSS and HTML and front-end technology layer diagram

Front-end technology layer (The picture is a bit e...

jQuery to achieve sliding stairs effect

This article shares the specific code of jQuery t...

Native Js implementation of calendar widget

This article example shares the specific code of ...

Tutorial on importing and exporting Docker containers

background The popularity of Docker is closely re...

How to use React slots

Table of contents need Core Idea Two ways to impl...

MySQL cross-database transaction XA operation example

This article uses an example to describe the MySQ...