Why does a Linux system have w permissions but cannot delete files?

  
                

There are some caveats when the Linux system deletes files. If you don't notice these details, you can't delete files even if you have the w permission for a file. Here's a concrete demonstration of the scene of deleting files, to show you why the Linux system has w permissions but can not delete files.

Scene Simulation:

root User

[root@mode-6 ~]# mkdir /oldboy/

[root@mode-6 /] # ll /oldboy/-d

drwxr-xr-x 2 root root 4096 Nov 27 15:46 /oldboy/

[root@mode-6 ~]# cd /oldboy/< Br>

[root@mode-6 oldboy]# vim test1.sh

echo ‘My name Is ZhangLiang.’

[root@mode-6 oldboy]# ll

total 4

-rw-r--r-- 1 root root 30 Nov 27 15:44 test1.sh

Ordinary users

[ Oldboy@mode-6 oldboy]$ cat test1.sh

echo ‘My name Is ZhangLiang.’

[oldboy@mode-6 oldboy]$ echo “12312” 》 Test1.sh

-bash: test1.sh: Permission denied # Insufficient permissions

[oldboy@mode-6 oldboy]$ . /test1.sh

-bash: . /test1.sh: Permission denied# Insufficient permissions

root user

[root@mode-6 oldboy]# chmod 747 test1.sh

[root@mode-6 Oldboy]# ll

total 4

-rwxr--rwx 1 root root 30 Nov 27 15:44 test1.sh

This is a rwx operation with other users Can be successfully executed. However, it fails when deleting.

[oldboy@mode-6 oldboy]$ rm -f test1.sh

rm: cannot remove `test1.sh‘: Permission denied # Permission denied < Br>

The file name is saved in the block of the parent directory, so whether the file can be deleted depends on whether the upper directory has the corresponding w permission.

[root@mode-6 /]# ll /oldboy/-d

drwxr-xr-x 2 root root 4096 Nov 27 15:46 /oldboy/# Other users do not have w permission . So you can't delete

[root@mode-6 /]# chmod 757 . /oldboy/# root user

[root@mode-6 /]# ll /oldboy/-d

drwxr-xrwx 2 root root 4096 Nov 27 15:46 /oldboy/# Permissions Modified

[oldboy@mode-6 oldboy]$ rm -f test1.sh # Normal user can be successfully deleted

############## ################################################################################################## #####br>

################################################################################## Said rwx

where r: represents the contents of the read directory

w: delete, modify the permissions of the file name in the directory [must be executed with x]

x : Can the representative enter the directory?

Through the above demonstration, do you know why the Linux system has the w permission but cannot delete the file? After reading this article, you can avoid the same problem the next time you delete a file.

Copyright © Windows knowledge All Rights Reserved