Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to deal with folder permissions in Linux

Shulou Source: shulou.com Published: 2022-06-01 06:39:59 10月15日 Update

Xiaobian to share with you how to deal with folder permissions in Linux, I believe most people still do not know how to share this article for your reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

File permissions under Linux

r(read): can read the contents of the file

w(write): You can edit and modify the content of the file

x(execute): This file can be executed

It is important to note that these permissions are specific to the content of the file and have nothing to do with the file itself. Therefore, even if you have rwx permissions on files, you may not be able to rename or delete files.

Folder permissions under Linux

r(read): You can read the folder contents list, but without x permission, you can only see the file name and cannot view other contents (size, permissions, etc.)

w(write): Because the folder record is a list of its contents, you can modify this list with w permission, provided you have x permission to enter this directory. W specifically has the following permissions:

Create a new file or folder

Delete an existing file or folder (regardless of permissions on the file or folder)

Renaming an existing file or folder

Change the location of a file or folder in a directory

x(execute): You can enter this folder. Without x permission, you cannot execute any command under this directory.

It should be noted here that since the directory regards all files under it as its contents, the file rename and delete permissions are included in the w permissions of the file parent directory by Linux. When a user renames or deletes a file (folder), what is performed is the w operation on the directory above it, and because of this, deleting a file (folder) can ignore its own permission settings.

After that, I thought of a problem and entangled myself: everything under Linux is a file, and there are files and folders, so is the Linux root directory (/) a folder?

The reason for this strange problem is that I found that in Linux root directory (/), it seems that only root user has the right to delete files. From the above analysis, it can be seen that deleting a file is to perform the w operation of the upper directory of the file, and the upper layer of the file under the root directory is naturally the root directory. Well, maybe/not necessarily a folder, just a mount point? I don't know. I'll leave it for later.

root@ubuntu:/# touch file

root@ubuntu:/# chmod 777 file

root@ubuntu:/# chown slyar file

root@ubuntu:/# ls -l | grep file

-rwxrwxrwx 1 slyar slyar 0 2009-08-09 17:11 file

root@ubuntu:/# su slyar

slyar@ubuntu:/$ rm -f file

rm: cannot remove `file': Permission denied

PS. Aha, just on the Ubuntu Chinese forum asked the next senior, immediately someone to help me answer. "/" is a folder (of course, its essence or a file) with the following command can be viewed, and you can change permissions at will, the problem solved!

root@ubuntu:/# ls -ld /

drwxr-xr-x 22 root root 4096 2009-08-09 17:28 /

The above is "How to handle folder permissions in Linux" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Tags: Files permissions folders contents directories root directories questions articles processing upper layers commands users nature not much location premise seniors only size most Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information MySQL MariaDB Apple Shulou Technology