Home >Operation and Maintenance >Linux Operation and Maintenance >Default permissions of files under Linux system and the role of hidden attributes

Default permissions of files under Linux system and the role of hidden attributes

齐天大圣
齐天大圣Original
2020-09-13 16:00:242162browse

File default permissions

When we create a file, the file will be set with default permissions by default.

# touch 1.txt
# ls -l 1.txt 
-rw-r--r-- 1 root root 0 Sep 13 14:48 1.txt

# mkdir abc
# ll -d abc
drwxr-xr-x 2 root root 4096 Sep 13 14:51 abc

You can see that the newly created file permissions are 644 and the directory permissions are 755. So where did this 644 come from? It turns out that the system will give default permissions to newly created files. This default permissions can be viewed through umask.

# umask
0022

# umask -S
u=rwx,g=rx,o=rx

The permissions viewed through umask -S are the default permissions of the newly created directory. If the newly created file type is a file, x permissions need to be subtracted, so the default permissions of the new file are 644 (rw -r-xr-x)

We can also modify the default permissions of the file through umask

umask 770

File hidden attributes

I don’t know if you have used Pagoda. When we create a new site through Pagoda, Pagoda will create a .user.ini file in the root directory of the website by default. This file is very strange. Even if you are a root user, you cannot delete it. The following prompt message will appear:

# rm -f .user.ini 
rm: cannot remove ‘.user.ini’: Operation not permitted

Here we want to talk about another concept, the hidden attributes of files. Why are they called hidden attributes? Because you can't see anything different about this file through ls -l.

# ll .user.ini 
-rw-r--r-- 1 root root 51 Sep  5 18:48 .user.ini

If you want to see something strange, you need to use lsattr to check

# lsattr .user.ini 
----i--------e-- .user.ini

Here, we need to remember the meaning of a few characters:

  • i means that the system does not allow any modification to this file. If the directory has this attribute, then any process can only modify the files under the directory, and is not allowed to create or delete files.

  • a means that the system only allows appending data after this file and does not allow any process to overwrite or truncate this file. If a directory has this attribute, the system will only allow files to be created and modified in this directory, but will not allow any files to be deleted.

So, if we want to delete this file, we need to modify its hidden attributes. It can be done through chattr.

# chattr -i .user.ini 
# rm -f .user.ini  <===删除成功了

The above is the detailed content of Default permissions of files under Linux system and the role of hidden attributes. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn