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

齐天大圣
Release: 2020-09-14 09:31:04
Original
1957 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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

# lsattr .user.ini 
----i--------e-- .user.ini
Copy after login

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  <===删除成功了
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!