2

As you can see below the root user cannot remove myapp directory but can write and delete files in this directory. The filesystem is ext4. Is this a filesystem issue? Do you have any ideas on it?

root@vm4923:/opt/tomcat/webapps# ls -l | grep myapp
drwxr-xr-x  2 root root     4096 Feb 17 14:30 myapp
-rw-r--r--  1 root root 17544487 Dec 18 12:59 myapp.war

root@vm4923:/opt/tomcat/webapps# rm -rf myapp
rm: cannot remove 'myapp': Permission denied

root@vm4923:/opt/tomcat/webapps# sudo rm -rf myapp
rm: cannot remove 'myapp': Permission denied

root@vm4923:/opt/tomcat/webapps# ls -l myapp/
total 0

root@vm4923:/opt/tomcat/webapps# echo "jsdkfjslkdj" > myapp/testfile

root@vm4923:/opt/tomcat/webapps# ls -l myapp/
total 4
-rw-r--r-- 1 root root 12 Feb 17 14:38 testfile

root@vm4923:/opt/tomcat/webapps# ls -lh | grep myapp
drwxr-xr-x  2 root root 4.0K Feb 17 14:38 myapp
-rw-r--r--  1 root root  17M Dec 18 12:59 myapp.war

root@vm4923:/opt/tomcat/webapps# ls -l myapp/
total 4
-rw-r--r-- 1 root root 12 Feb 17 14:38 testfile

root@vm4923:/opt/tomcat/webapps# rm -rf myapp
rm: cannot remove 'myapp': Permission denied

root@vm4923:/opt/tomcat/webapps# ls -l myapp/
total 0
root@vm4923:/opt/tomcat/webapps# ls -lh | grep myapp
drwxr-xr-x  2 root root 4.0K Feb 17 14:39 myapp
-rw-r--r--  1 root root  17M Dec 18 12:59 myapp.war
root@vm4923:/opt/tomcat/webapps# 

@Fiximan

# ls -l | grep webapps
drwxrwxrwx 9 root root  4096 Jan 27 21:41 webapps

@jcbermu lsattr's output after issuing # chattr -i examp command:

# lsattr 
-------------e-- ./myapp
-------------e-- ./host-manager
-------------e-- ./myapp.war
-------------e-- ./examples
-------------e-- ./docs
-------------e-- ./examp
-------------e-- ./examp.war
-------------e-- ./ROOT
-------------e-- ./manager

The solution (edit)

Finally, the root cause of the problem was on the ext4 attributes (not the permissions) of the parent directory.

root@vm4923:/opt/tomcat# lsattr | grep webapps
----i--------e-- ./webapps

By removing the i attribute from webapps directory I got able to remove myapp directory using rm -rf command.

root@vm4923:/opt/tomcat# chattr -i webapps

root@vm4923:/opt/tomcat# lsattr | grep webapps
-------------e-- ./webapps

root@vm4923:/opt/tomcat# cd webapps/

root@vm4923:/opt/tomcat/webapps# ls
ROOT  docs  examp  examp.war  examples  host-manager  manager  myapp  myapp.war

root@vm4923:/opt/tomcat/webapps# ls myapp
testdir

root@vm4923:/opt/tomcat/webapps# rm -rf myapp

root@vm4923:/opt/tomcat/webapps# ls
ROOT  docs  examp  examp.war  examples  host-manager  manager  myapp.war

Thank you guys for your effort!

  • what are the permissions for the parent folder /opt/tomcat/webapps ? – Fiximan Feb 17 '16 at 14:33
  • @Fiximan # ls -l | grep webapps drwxrwxrwx 9 root root 4096 Jan 27 21:41 webapps – funk Feb 17 '16 at 14:38
6

To combine both answers:

check if the parent directory webapps has the i or a attributes set by

lsattr | grep webapps

Then, remove them via

chattr -i -a webapps
| improve this answer | |
3

Being root check the attributes of files issuing the following command:

lsattr 

The output should be like this:

-----------------e- ./.thisfolder/.
-----------------e- ./.thisfolder/somefile

if you notice and i or a remove them with:

chattr -i [filename]
chattr -a [filename]

chattr allows in ext2, ext3 and ext4 filesystemsto modify attributes that override ACLs (chmod, chown,setfacl…) giving you a tight control over the files.

The most common attributes are:

  • (A) Don't update atime

  • (S) synchronous updates

  • (a) append only

  • (d) no dump

  • (i) immutable

  • (j) data journalling

  • (t) no tail-merging

lsattr simply list those attributes.

| improve this answer | |
  • @funk You have an i on examp – jcbermu Feb 17 '16 at 14:33
  • I updated the initial post. The problem still remains after issuing chattr -i examp command. – funk Feb 17 '16 at 14:42
2

It's a common misbelief that to remove directory /a/b/c one has to have the write permission on /a/b/c. Having that right grants you to manipulate the CONTENT of /a/b/c that is to write/modify/delete files under it.

Hence, to remove /a/b/c you must have the write flag on /a/b

| improve this answer | |
  • Unless you're root, in which case the basic permissions are ignored. – ams Feb 17 '16 at 14:48
  • True. Shame on me for missing the id in the question. – Gombai Sándor Feb 17 '16 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.