What are the file attributes for linux crw brw lrw and so on

  • 2020-11-30 08:44:48
  • OfStack

What is a file?

In fact, all files are 1 string of characters stream, but when the appropriate parsing method is used, effective information can be obtained. In order to facilitate the operation of files, people give different types of files according to the different parsing methods of files, and mark them for people to see in the following way.

Today, when I was checking the attributes of /dev/fuse file, I saw the crw_ permission bit. I couldn't react after 1:


[root@localhost ~]# ll /dev/fuse
crw-rw-rw-. 1 root root 10, 229 Sep 20 11:12 /dev/fuse

Note 1 here, the relevant answers come from the network.

In linux, c means character device file, b means block device file, l means symbolic link file, r means read permission and w means write permission.

linux file attribute interpretation:

File type:

- : Ordinary file (f)
d: Directory files
b: Block device file (block)
c: Character device file (character)
l: Symbolic link file (symbolic link file)
p: Command pipe file (pipe)
s: Socket file (socket)
File permissions: 9 bits, 1 group for every 3 bits, 1 group for every 1: rwx(read, write, execute), use - instead of 1 permissions when shuffled.
The first group is: permissions for the file owner, who can read and write to the file but cannot execute it;
Group 2 is: permissions for the same group
Group 3 is: other permissions that are not in this group

Take a look at the file types in linux

(1) Ordinary file ('-', regluar file)

Divided into: 2 base files and text files

Base 2 files, for example:.bin,.elf files

Text files: for people to see, 1 usually ASCII encoding, need to be parsed with ASCII encoding, for example:.txt,.c file.

(2) Folder files ('d ', directory file)

A special file that needs to be opened with its library functions.

(3) Link file ('l', link file)

Here's the soft connection file,

Note: The difference between soft-connected files and hard-linked files,

The soft connection file is itself a separate file with its own inode,

Hard linked files, not separate files, share 1 inode with linked files.

(4) Pipe file ('p', piple file)

Used for process communication.

(5) Socket files ('s', socket file)

Used for networking.

(6) Character device file ('c', character file)

Created by fs for virtual files, as they do not exist on the hard disk.

You cannot read or write directly. Use API.

(7) Block device files ('b', block file)

Also a virtual file, created for fd, to be read and written using API.

3. How do I get the properties of a file?

(1) stat is used in shell

(2) stat API is used in the program

4. Permission to file

(1) How to obtain file permissions?

Using stat API in the program, you can obtain the st_mode element. st_mode is a record of content in bits, so only the corresponding bit is needed & That's it. linux provides the corresponding macro, which you can use.

(2) How to determine whether the program has permission to the file?

The file permissions, first of all, the procedure is determined by the execution of user, user permissions, program is, the user is not, program, there is no, then determine whether have permission to use in your application access API, finally, good program start first to operate in the implementation of the file permissions, if there is no authority, need to remind the users.

(3) How to modify permissions?

There is chmod in shell, and there is chmod API as well, so use this API.

(4) How to determine the permissions of newly created files?

linux has something like an umask variable, and permissions for new files are determined by umask. umask can be changed in shell.

conclusion


Related articles: