Why is “rm -r” unable to delete this folder?I can not remove folder from serverAdding supllimentary group...
How to not let the Identify spell spoil everything?
Why did Ylvis use "go" instead of "say" in phrases like "Dog goes 'woof'"?
Why write a book when there's a movie in my head?
If I tried and failed to start my own business, how do I apply for a job without job experience?
What could cause an entire planet of humans to become aphasic?
How do I avoid the "chosen hero" feeling?
How unreachable are Jupiter's moons from Mars with the technology developed for going to Mars?
Identical projects by students at two different colleges: still plagiarism?
Are all power cords made equal?
Stuck to wireframe
Minimum Viable Product for RTS game?
Does copper wire need to say it's copper?
Why might frozen potatoes require a hechsher?
Is Screenshot Time-tracking Common?
Solving the linear first order differential equation?
Modern Algebraic Geometry and Analytic Number Theory
Can you say "leftside right"?
Why is Shelob considered evil?
How can I automatically launch GPSD on startup?
Isn't a semicolon (';') needed after a function declaration in C++?
Bug in VectorFieldPlot[] with InterpolatingFunction[]?
What is an explicit bijection in combinatorics?
What species should be used for storage of human minds?
Why does a single AND gate need 60 transistors?
Why is “rm -r” unable to delete this folder?
I can not remove folder from serverAdding supllimentary group so that user can have accesssetfacl default --x on directories and r— on files for userFolder with ONLY write permission is useless… right?Unable to delete a file on different user's directoryFTP issues- Can't delete (empty) foldersAccess denied on folders for users though they have the rwx permission on SUSE LinuxPermissions folder/parent folderFolder group ownership permissions and problemsChanging permissions in a Unix directory
I have a folder with -wx
permissions called folder1
and another folder inside it called folder2
with rwx
permissions.
I tried to delete folder1
using this command:
rm -r folder1
But I got the following error:
rm: cannot remove 'folder1': Permission denied
The reason I think I got this error is because the rm
program needs to first get the content of folder1
(get the names of the files and folders inside folder1
that is) in order to be able to delete that content (because you can't delete a file or folder without knowing its name I think), and then the rm
program can delete folder1
itself.
But since folder1
doesn't have the read
permission, then the rm
program can't get its content, and hence it can't delete its content, and since it can't delete its content, then it can't delete it.
Am I correct?
linux permissions rm
add a comment |
I have a folder with -wx
permissions called folder1
and another folder inside it called folder2
with rwx
permissions.
I tried to delete folder1
using this command:
rm -r folder1
But I got the following error:
rm: cannot remove 'folder1': Permission denied
The reason I think I got this error is because the rm
program needs to first get the content of folder1
(get the names of the files and folders inside folder1
that is) in order to be able to delete that content (because you can't delete a file or folder without knowing its name I think), and then the rm
program can delete folder1
itself.
But since folder1
doesn't have the read
permission, then the rm
program can't get its content, and hence it can't delete its content, and since it can't delete its content, then it can't delete it.
Am I correct?
linux permissions rm
add a comment |
I have a folder with -wx
permissions called folder1
and another folder inside it called folder2
with rwx
permissions.
I tried to delete folder1
using this command:
rm -r folder1
But I got the following error:
rm: cannot remove 'folder1': Permission denied
The reason I think I got this error is because the rm
program needs to first get the content of folder1
(get the names of the files and folders inside folder1
that is) in order to be able to delete that content (because you can't delete a file or folder without knowing its name I think), and then the rm
program can delete folder1
itself.
But since folder1
doesn't have the read
permission, then the rm
program can't get its content, and hence it can't delete its content, and since it can't delete its content, then it can't delete it.
Am I correct?
linux permissions rm
I have a folder with -wx
permissions called folder1
and another folder inside it called folder2
with rwx
permissions.
I tried to delete folder1
using this command:
rm -r folder1
But I got the following error:
rm: cannot remove 'folder1': Permission denied
The reason I think I got this error is because the rm
program needs to first get the content of folder1
(get the names of the files and folders inside folder1
that is) in order to be able to delete that content (because you can't delete a file or folder without knowing its name I think), and then the rm
program can delete folder1
itself.
But since folder1
doesn't have the read
permission, then the rm
program can't get its content, and hence it can't delete its content, and since it can't delete its content, then it can't delete it.
Am I correct?
linux permissions rm
linux permissions rm
edited 20 mins ago
psmears
44328
44328
asked 10 hours ago
JohnJohn
1886
1886
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I think your analysis is correct: you cannot delete the directory since its non-empty, and you cannot empty it since you cannot see its contents.
EDIT: I just gave it a try:
$ mkdir -p folder1/folder2
$ chmod -r folder1
$ rm -rf folder1
rm: cannot remove 'folder1': Permission denied
$ rmdir folder1/folder2
$ rm -rf folder1
$
EDIT 2: When I wrote “you”, I meant any program you may run. Your rm -r
command first sees that folder1
is a directory, so it tries to discover its contents to empty it, but fails for missing read permission, then it tries to delete it but fails because it’s non-empty. The “Permission denied” is misleading; I think “Directory not empty” (like rmdir
reports) would be more appropriate.)
3
It can't reportDirectory not empty
in this case since it would not know it was empty or not. You would still get the same error when trying to delete an empty directory that you don't have read permissions on. (Also, please disregard my previous comment, I didn't have my thinking cap on).
– Kusalananda
10 hours ago
@Kusalananda That sounds sane, butrmdir
is able to report “Directory not empty”. And if you read my test, you’ll see that it accepts to remove thefolder1
directory, with no read permission, once I have emptied it.
– user2233709
9 hours ago
Your test shows an interesting difference between our systems. I get aPermission denied
when trying torm -r folder1
when it's empty. I'm on OpenBSD, not Linux.
– Kusalananda
9 hours ago
@Kusalananda That’s interesting. I would have thought that this behavior was specified by the Single Unix Specification, so that Linux and {Free,Net,Open}BSD would behave identically. (For the record, I am using Debian Stretch 9.8 with a linux 4.9.144-3 x86_64 kernel.)
– user2233709
8 hours ago
Hmm... The only thing that POSIX says is that if the operand is a directory and-r
is used, each directory entry (except for.
and..
) should be removed as if they were a file operand ofrm -r
. It appears as if GNUrm
simply does armdir()
on the directory if it's not readable, because it will have no way to get the contents of it.
– Kusalananda
8 hours ago
|
show 3 more comments
For deletion to occur the system must be able to read the contents and identify what has to be deleted.
I've tried simulating what you are attempting :
[vagrant@desktop1 ~]$ sudo rm -rf folder1/ && mkdir -pv folder1/folder2 && sudo chmod 333 -v folder1/ && sudo chmod 777 -v folder1/folder2
mkdir: created directory 'folder1'
mkdir: created directory 'folder1/folder2'
mode of 'folder1/' changed from 0775 (rwxrwxr-x) to 0333 (-wx-wx-wx)
mode of 'folder1/folder2' changed from 0775 (rwxrwxr-x) to 0777 (rwxrwxrwx)
[vagrant@desktop1 ~]$ ls -lh
total 0
d-wx-wx-wx. 3 vagrant vagrant 21 Feb 24 10:40 folder1
[vagrant@desktop1 ~]$
If we try deleting without read permissions it fails:
[vagrant@desktop1 ~]$ rm -r folder1/
rm: cannot remove 'folder1/': Permission denied
[vagrant@desktop1 ~]$ sudo chmod +r folder1/
[vagrant@desktop1 ~]$ rm -r folder1/
[vagrant@desktop1 ~]$
In an strace for the two attempts the difference is that the directory contents cannot be read (getdents):
newfstatat(AT_FDCWD, "folder1/", {st_mode=S_IFDIR|0333, st_size=21, ...}, AT_SYMLINK_NOFOLLOW) = 0
openat(AT_FDCWD, "folder1/", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_DIRECTORY|O_NOFOLLOW) = -1 EACCES (Permission denied)
geteuid() = 1000
newfstatat(AT_FDCWD, "folder1/", {st_mode=S_IFDIR|0333, st_size=21, ...}, AT_SYMLINK_NOFOLLOW) = 0
faccessat(AT_FDCWD, "folder1/", W_OK) = 0
openat(AT_FDCWD, "folder1/", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_DIRECTORY|O_NOFOLLOW) = -1 EACCES (Permission denied)
newfstatat(AT_FDCWD, "folder1/", {st_mode=S_IFDIR|0333, st_size=21, ...}, AT_SYMLINK_NOFOLLOW) = 0
With read permissions:
newfstatat(AT_FDCWD, "folder1/", {st_mode=S_IFDIR|0777, st_size=21, ...}, AT_SYMLINK_NOFOLLOW) = 0
openat(AT_FDCWD, "folder1/", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_DIRECTORY|O_NOFOLLOW) = 3
fstat(3, {st_mode=S_IFDIR|0777, st_size=21, ...}) = 0
fcntl(3, F_GETFL) = 0x38800 (flags O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_NOFOLLOW)
fcntl(3, F_SETFD, FD_CLOEXEC) = 0
getdents(3, /* 3 entries */, 32768) = 80
close(3) = 0
geteuid() = 1000
To conclude even if you own a directory and it has the executable bit, you still need read permissions so that you may see its contents and delete the folder. It's not the same for a file though.
Kind regards,
Taran.
New contributor
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f502659%2fwhy-is-rm-r-unable-to-delete-this-folder%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think your analysis is correct: you cannot delete the directory since its non-empty, and you cannot empty it since you cannot see its contents.
EDIT: I just gave it a try:
$ mkdir -p folder1/folder2
$ chmod -r folder1
$ rm -rf folder1
rm: cannot remove 'folder1': Permission denied
$ rmdir folder1/folder2
$ rm -rf folder1
$
EDIT 2: When I wrote “you”, I meant any program you may run. Your rm -r
command first sees that folder1
is a directory, so it tries to discover its contents to empty it, but fails for missing read permission, then it tries to delete it but fails because it’s non-empty. The “Permission denied” is misleading; I think “Directory not empty” (like rmdir
reports) would be more appropriate.)
3
It can't reportDirectory not empty
in this case since it would not know it was empty or not. You would still get the same error when trying to delete an empty directory that you don't have read permissions on. (Also, please disregard my previous comment, I didn't have my thinking cap on).
– Kusalananda
10 hours ago
@Kusalananda That sounds sane, butrmdir
is able to report “Directory not empty”. And if you read my test, you’ll see that it accepts to remove thefolder1
directory, with no read permission, once I have emptied it.
– user2233709
9 hours ago
Your test shows an interesting difference between our systems. I get aPermission denied
when trying torm -r folder1
when it's empty. I'm on OpenBSD, not Linux.
– Kusalananda
9 hours ago
@Kusalananda That’s interesting. I would have thought that this behavior was specified by the Single Unix Specification, so that Linux and {Free,Net,Open}BSD would behave identically. (For the record, I am using Debian Stretch 9.8 with a linux 4.9.144-3 x86_64 kernel.)
– user2233709
8 hours ago
Hmm... The only thing that POSIX says is that if the operand is a directory and-r
is used, each directory entry (except for.
and..
) should be removed as if they were a file operand ofrm -r
. It appears as if GNUrm
simply does armdir()
on the directory if it's not readable, because it will have no way to get the contents of it.
– Kusalananda
8 hours ago
|
show 3 more comments
I think your analysis is correct: you cannot delete the directory since its non-empty, and you cannot empty it since you cannot see its contents.
EDIT: I just gave it a try:
$ mkdir -p folder1/folder2
$ chmod -r folder1
$ rm -rf folder1
rm: cannot remove 'folder1': Permission denied
$ rmdir folder1/folder2
$ rm -rf folder1
$
EDIT 2: When I wrote “you”, I meant any program you may run. Your rm -r
command first sees that folder1
is a directory, so it tries to discover its contents to empty it, but fails for missing read permission, then it tries to delete it but fails because it’s non-empty. The “Permission denied” is misleading; I think “Directory not empty” (like rmdir
reports) would be more appropriate.)
3
It can't reportDirectory not empty
in this case since it would not know it was empty or not. You would still get the same error when trying to delete an empty directory that you don't have read permissions on. (Also, please disregard my previous comment, I didn't have my thinking cap on).
– Kusalananda
10 hours ago
@Kusalananda That sounds sane, butrmdir
is able to report “Directory not empty”. And if you read my test, you’ll see that it accepts to remove thefolder1
directory, with no read permission, once I have emptied it.
– user2233709
9 hours ago
Your test shows an interesting difference between our systems. I get aPermission denied
when trying torm -r folder1
when it's empty. I'm on OpenBSD, not Linux.
– Kusalananda
9 hours ago
@Kusalananda That’s interesting. I would have thought that this behavior was specified by the Single Unix Specification, so that Linux and {Free,Net,Open}BSD would behave identically. (For the record, I am using Debian Stretch 9.8 with a linux 4.9.144-3 x86_64 kernel.)
– user2233709
8 hours ago
Hmm... The only thing that POSIX says is that if the operand is a directory and-r
is used, each directory entry (except for.
and..
) should be removed as if they were a file operand ofrm -r
. It appears as if GNUrm
simply does armdir()
on the directory if it's not readable, because it will have no way to get the contents of it.
– Kusalananda
8 hours ago
|
show 3 more comments
I think your analysis is correct: you cannot delete the directory since its non-empty, and you cannot empty it since you cannot see its contents.
EDIT: I just gave it a try:
$ mkdir -p folder1/folder2
$ chmod -r folder1
$ rm -rf folder1
rm: cannot remove 'folder1': Permission denied
$ rmdir folder1/folder2
$ rm -rf folder1
$
EDIT 2: When I wrote “you”, I meant any program you may run. Your rm -r
command first sees that folder1
is a directory, so it tries to discover its contents to empty it, but fails for missing read permission, then it tries to delete it but fails because it’s non-empty. The “Permission denied” is misleading; I think “Directory not empty” (like rmdir
reports) would be more appropriate.)
I think your analysis is correct: you cannot delete the directory since its non-empty, and you cannot empty it since you cannot see its contents.
EDIT: I just gave it a try:
$ mkdir -p folder1/folder2
$ chmod -r folder1
$ rm -rf folder1
rm: cannot remove 'folder1': Permission denied
$ rmdir folder1/folder2
$ rm -rf folder1
$
EDIT 2: When I wrote “you”, I meant any program you may run. Your rm -r
command first sees that folder1
is a directory, so it tries to discover its contents to empty it, but fails for missing read permission, then it tries to delete it but fails because it’s non-empty. The “Permission denied” is misleading; I think “Directory not empty” (like rmdir
reports) would be more appropriate.)
edited 10 hours ago
answered 10 hours ago
user2233709user2233709
993312
993312
3
It can't reportDirectory not empty
in this case since it would not know it was empty or not. You would still get the same error when trying to delete an empty directory that you don't have read permissions on. (Also, please disregard my previous comment, I didn't have my thinking cap on).
– Kusalananda
10 hours ago
@Kusalananda That sounds sane, butrmdir
is able to report “Directory not empty”. And if you read my test, you’ll see that it accepts to remove thefolder1
directory, with no read permission, once I have emptied it.
– user2233709
9 hours ago
Your test shows an interesting difference between our systems. I get aPermission denied
when trying torm -r folder1
when it's empty. I'm on OpenBSD, not Linux.
– Kusalananda
9 hours ago
@Kusalananda That’s interesting. I would have thought that this behavior was specified by the Single Unix Specification, so that Linux and {Free,Net,Open}BSD would behave identically. (For the record, I am using Debian Stretch 9.8 with a linux 4.9.144-3 x86_64 kernel.)
– user2233709
8 hours ago
Hmm... The only thing that POSIX says is that if the operand is a directory and-r
is used, each directory entry (except for.
and..
) should be removed as if they were a file operand ofrm -r
. It appears as if GNUrm
simply does armdir()
on the directory if it's not readable, because it will have no way to get the contents of it.
– Kusalananda
8 hours ago
|
show 3 more comments
3
It can't reportDirectory not empty
in this case since it would not know it was empty or not. You would still get the same error when trying to delete an empty directory that you don't have read permissions on. (Also, please disregard my previous comment, I didn't have my thinking cap on).
– Kusalananda
10 hours ago
@Kusalananda That sounds sane, butrmdir
is able to report “Directory not empty”. And if you read my test, you’ll see that it accepts to remove thefolder1
directory, with no read permission, once I have emptied it.
– user2233709
9 hours ago
Your test shows an interesting difference between our systems. I get aPermission denied
when trying torm -r folder1
when it's empty. I'm on OpenBSD, not Linux.
– Kusalananda
9 hours ago
@Kusalananda That’s interesting. I would have thought that this behavior was specified by the Single Unix Specification, so that Linux and {Free,Net,Open}BSD would behave identically. (For the record, I am using Debian Stretch 9.8 with a linux 4.9.144-3 x86_64 kernel.)
– user2233709
8 hours ago
Hmm... The only thing that POSIX says is that if the operand is a directory and-r
is used, each directory entry (except for.
and..
) should be removed as if they were a file operand ofrm -r
. It appears as if GNUrm
simply does armdir()
on the directory if it's not readable, because it will have no way to get the contents of it.
– Kusalananda
8 hours ago
3
3
It can't report
Directory not empty
in this case since it would not know it was empty or not. You would still get the same error when trying to delete an empty directory that you don't have read permissions on. (Also, please disregard my previous comment, I didn't have my thinking cap on).– Kusalananda
10 hours ago
It can't report
Directory not empty
in this case since it would not know it was empty or not. You would still get the same error when trying to delete an empty directory that you don't have read permissions on. (Also, please disregard my previous comment, I didn't have my thinking cap on).– Kusalananda
10 hours ago
@Kusalananda That sounds sane, but
rmdir
is able to report “Directory not empty”. And if you read my test, you’ll see that it accepts to remove the folder1
directory, with no read permission, once I have emptied it.– user2233709
9 hours ago
@Kusalananda That sounds sane, but
rmdir
is able to report “Directory not empty”. And if you read my test, you’ll see that it accepts to remove the folder1
directory, with no read permission, once I have emptied it.– user2233709
9 hours ago
Your test shows an interesting difference between our systems. I get a
Permission denied
when trying to rm -r folder1
when it's empty. I'm on OpenBSD, not Linux.– Kusalananda
9 hours ago
Your test shows an interesting difference between our systems. I get a
Permission denied
when trying to rm -r folder1
when it's empty. I'm on OpenBSD, not Linux.– Kusalananda
9 hours ago
@Kusalananda That’s interesting. I would have thought that this behavior was specified by the Single Unix Specification, so that Linux and {Free,Net,Open}BSD would behave identically. (For the record, I am using Debian Stretch 9.8 with a linux 4.9.144-3 x86_64 kernel.)
– user2233709
8 hours ago
@Kusalananda That’s interesting. I would have thought that this behavior was specified by the Single Unix Specification, so that Linux and {Free,Net,Open}BSD would behave identically. (For the record, I am using Debian Stretch 9.8 with a linux 4.9.144-3 x86_64 kernel.)
– user2233709
8 hours ago
Hmm... The only thing that POSIX says is that if the operand is a directory and
-r
is used, each directory entry (except for .
and ..
) should be removed as if they were a file operand of rm -r
. It appears as if GNU rm
simply does a rmdir()
on the directory if it's not readable, because it will have no way to get the contents of it.– Kusalananda
8 hours ago
Hmm... The only thing that POSIX says is that if the operand is a directory and
-r
is used, each directory entry (except for .
and ..
) should be removed as if they were a file operand of rm -r
. It appears as if GNU rm
simply does a rmdir()
on the directory if it's not readable, because it will have no way to get the contents of it.– Kusalananda
8 hours ago
|
show 3 more comments
For deletion to occur the system must be able to read the contents and identify what has to be deleted.
I've tried simulating what you are attempting :
[vagrant@desktop1 ~]$ sudo rm -rf folder1/ && mkdir -pv folder1/folder2 && sudo chmod 333 -v folder1/ && sudo chmod 777 -v folder1/folder2
mkdir: created directory 'folder1'
mkdir: created directory 'folder1/folder2'
mode of 'folder1/' changed from 0775 (rwxrwxr-x) to 0333 (-wx-wx-wx)
mode of 'folder1/folder2' changed from 0775 (rwxrwxr-x) to 0777 (rwxrwxrwx)
[vagrant@desktop1 ~]$ ls -lh
total 0
d-wx-wx-wx. 3 vagrant vagrant 21 Feb 24 10:40 folder1
[vagrant@desktop1 ~]$
If we try deleting without read permissions it fails:
[vagrant@desktop1 ~]$ rm -r folder1/
rm: cannot remove 'folder1/': Permission denied
[vagrant@desktop1 ~]$ sudo chmod +r folder1/
[vagrant@desktop1 ~]$ rm -r folder1/
[vagrant@desktop1 ~]$
In an strace for the two attempts the difference is that the directory contents cannot be read (getdents):
newfstatat(AT_FDCWD, "folder1/", {st_mode=S_IFDIR|0333, st_size=21, ...}, AT_SYMLINK_NOFOLLOW) = 0
openat(AT_FDCWD, "folder1/", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_DIRECTORY|O_NOFOLLOW) = -1 EACCES (Permission denied)
geteuid() = 1000
newfstatat(AT_FDCWD, "folder1/", {st_mode=S_IFDIR|0333, st_size=21, ...}, AT_SYMLINK_NOFOLLOW) = 0
faccessat(AT_FDCWD, "folder1/", W_OK) = 0
openat(AT_FDCWD, "folder1/", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_DIRECTORY|O_NOFOLLOW) = -1 EACCES (Permission denied)
newfstatat(AT_FDCWD, "folder1/", {st_mode=S_IFDIR|0333, st_size=21, ...}, AT_SYMLINK_NOFOLLOW) = 0
With read permissions:
newfstatat(AT_FDCWD, "folder1/", {st_mode=S_IFDIR|0777, st_size=21, ...}, AT_SYMLINK_NOFOLLOW) = 0
openat(AT_FDCWD, "folder1/", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_DIRECTORY|O_NOFOLLOW) = 3
fstat(3, {st_mode=S_IFDIR|0777, st_size=21, ...}) = 0
fcntl(3, F_GETFL) = 0x38800 (flags O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_NOFOLLOW)
fcntl(3, F_SETFD, FD_CLOEXEC) = 0
getdents(3, /* 3 entries */, 32768) = 80
close(3) = 0
geteuid() = 1000
To conclude even if you own a directory and it has the executable bit, you still need read permissions so that you may see its contents and delete the folder. It's not the same for a file though.
Kind regards,
Taran.
New contributor
add a comment |
For deletion to occur the system must be able to read the contents and identify what has to be deleted.
I've tried simulating what you are attempting :
[vagrant@desktop1 ~]$ sudo rm -rf folder1/ && mkdir -pv folder1/folder2 && sudo chmod 333 -v folder1/ && sudo chmod 777 -v folder1/folder2
mkdir: created directory 'folder1'
mkdir: created directory 'folder1/folder2'
mode of 'folder1/' changed from 0775 (rwxrwxr-x) to 0333 (-wx-wx-wx)
mode of 'folder1/folder2' changed from 0775 (rwxrwxr-x) to 0777 (rwxrwxrwx)
[vagrant@desktop1 ~]$ ls -lh
total 0
d-wx-wx-wx. 3 vagrant vagrant 21 Feb 24 10:40 folder1
[vagrant@desktop1 ~]$
If we try deleting without read permissions it fails:
[vagrant@desktop1 ~]$ rm -r folder1/
rm: cannot remove 'folder1/': Permission denied
[vagrant@desktop1 ~]$ sudo chmod +r folder1/
[vagrant@desktop1 ~]$ rm -r folder1/
[vagrant@desktop1 ~]$
In an strace for the two attempts the difference is that the directory contents cannot be read (getdents):
newfstatat(AT_FDCWD, "folder1/", {st_mode=S_IFDIR|0333, st_size=21, ...}, AT_SYMLINK_NOFOLLOW) = 0
openat(AT_FDCWD, "folder1/", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_DIRECTORY|O_NOFOLLOW) = -1 EACCES (Permission denied)
geteuid() = 1000
newfstatat(AT_FDCWD, "folder1/", {st_mode=S_IFDIR|0333, st_size=21, ...}, AT_SYMLINK_NOFOLLOW) = 0
faccessat(AT_FDCWD, "folder1/", W_OK) = 0
openat(AT_FDCWD, "folder1/", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_DIRECTORY|O_NOFOLLOW) = -1 EACCES (Permission denied)
newfstatat(AT_FDCWD, "folder1/", {st_mode=S_IFDIR|0333, st_size=21, ...}, AT_SYMLINK_NOFOLLOW) = 0
With read permissions:
newfstatat(AT_FDCWD, "folder1/", {st_mode=S_IFDIR|0777, st_size=21, ...}, AT_SYMLINK_NOFOLLOW) = 0
openat(AT_FDCWD, "folder1/", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_DIRECTORY|O_NOFOLLOW) = 3
fstat(3, {st_mode=S_IFDIR|0777, st_size=21, ...}) = 0
fcntl(3, F_GETFL) = 0x38800 (flags O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_NOFOLLOW)
fcntl(3, F_SETFD, FD_CLOEXEC) = 0
getdents(3, /* 3 entries */, 32768) = 80
close(3) = 0
geteuid() = 1000
To conclude even if you own a directory and it has the executable bit, you still need read permissions so that you may see its contents and delete the folder. It's not the same for a file though.
Kind regards,
Taran.
New contributor
add a comment |
For deletion to occur the system must be able to read the contents and identify what has to be deleted.
I've tried simulating what you are attempting :
[vagrant@desktop1 ~]$ sudo rm -rf folder1/ && mkdir -pv folder1/folder2 && sudo chmod 333 -v folder1/ && sudo chmod 777 -v folder1/folder2
mkdir: created directory 'folder1'
mkdir: created directory 'folder1/folder2'
mode of 'folder1/' changed from 0775 (rwxrwxr-x) to 0333 (-wx-wx-wx)
mode of 'folder1/folder2' changed from 0775 (rwxrwxr-x) to 0777 (rwxrwxrwx)
[vagrant@desktop1 ~]$ ls -lh
total 0
d-wx-wx-wx. 3 vagrant vagrant 21 Feb 24 10:40 folder1
[vagrant@desktop1 ~]$
If we try deleting without read permissions it fails:
[vagrant@desktop1 ~]$ rm -r folder1/
rm: cannot remove 'folder1/': Permission denied
[vagrant@desktop1 ~]$ sudo chmod +r folder1/
[vagrant@desktop1 ~]$ rm -r folder1/
[vagrant@desktop1 ~]$
In an strace for the two attempts the difference is that the directory contents cannot be read (getdents):
newfstatat(AT_FDCWD, "folder1/", {st_mode=S_IFDIR|0333, st_size=21, ...}, AT_SYMLINK_NOFOLLOW) = 0
openat(AT_FDCWD, "folder1/", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_DIRECTORY|O_NOFOLLOW) = -1 EACCES (Permission denied)
geteuid() = 1000
newfstatat(AT_FDCWD, "folder1/", {st_mode=S_IFDIR|0333, st_size=21, ...}, AT_SYMLINK_NOFOLLOW) = 0
faccessat(AT_FDCWD, "folder1/", W_OK) = 0
openat(AT_FDCWD, "folder1/", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_DIRECTORY|O_NOFOLLOW) = -1 EACCES (Permission denied)
newfstatat(AT_FDCWD, "folder1/", {st_mode=S_IFDIR|0333, st_size=21, ...}, AT_SYMLINK_NOFOLLOW) = 0
With read permissions:
newfstatat(AT_FDCWD, "folder1/", {st_mode=S_IFDIR|0777, st_size=21, ...}, AT_SYMLINK_NOFOLLOW) = 0
openat(AT_FDCWD, "folder1/", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_DIRECTORY|O_NOFOLLOW) = 3
fstat(3, {st_mode=S_IFDIR|0777, st_size=21, ...}) = 0
fcntl(3, F_GETFL) = 0x38800 (flags O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_NOFOLLOW)
fcntl(3, F_SETFD, FD_CLOEXEC) = 0
getdents(3, /* 3 entries */, 32768) = 80
close(3) = 0
geteuid() = 1000
To conclude even if you own a directory and it has the executable bit, you still need read permissions so that you may see its contents and delete the folder. It's not the same for a file though.
Kind regards,
Taran.
New contributor
For deletion to occur the system must be able to read the contents and identify what has to be deleted.
I've tried simulating what you are attempting :
[vagrant@desktop1 ~]$ sudo rm -rf folder1/ && mkdir -pv folder1/folder2 && sudo chmod 333 -v folder1/ && sudo chmod 777 -v folder1/folder2
mkdir: created directory 'folder1'
mkdir: created directory 'folder1/folder2'
mode of 'folder1/' changed from 0775 (rwxrwxr-x) to 0333 (-wx-wx-wx)
mode of 'folder1/folder2' changed from 0775 (rwxrwxr-x) to 0777 (rwxrwxrwx)
[vagrant@desktop1 ~]$ ls -lh
total 0
d-wx-wx-wx. 3 vagrant vagrant 21 Feb 24 10:40 folder1
[vagrant@desktop1 ~]$
If we try deleting without read permissions it fails:
[vagrant@desktop1 ~]$ rm -r folder1/
rm: cannot remove 'folder1/': Permission denied
[vagrant@desktop1 ~]$ sudo chmod +r folder1/
[vagrant@desktop1 ~]$ rm -r folder1/
[vagrant@desktop1 ~]$
In an strace for the two attempts the difference is that the directory contents cannot be read (getdents):
newfstatat(AT_FDCWD, "folder1/", {st_mode=S_IFDIR|0333, st_size=21, ...}, AT_SYMLINK_NOFOLLOW) = 0
openat(AT_FDCWD, "folder1/", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_DIRECTORY|O_NOFOLLOW) = -1 EACCES (Permission denied)
geteuid() = 1000
newfstatat(AT_FDCWD, "folder1/", {st_mode=S_IFDIR|0333, st_size=21, ...}, AT_SYMLINK_NOFOLLOW) = 0
faccessat(AT_FDCWD, "folder1/", W_OK) = 0
openat(AT_FDCWD, "folder1/", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_DIRECTORY|O_NOFOLLOW) = -1 EACCES (Permission denied)
newfstatat(AT_FDCWD, "folder1/", {st_mode=S_IFDIR|0333, st_size=21, ...}, AT_SYMLINK_NOFOLLOW) = 0
With read permissions:
newfstatat(AT_FDCWD, "folder1/", {st_mode=S_IFDIR|0777, st_size=21, ...}, AT_SYMLINK_NOFOLLOW) = 0
openat(AT_FDCWD, "folder1/", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_DIRECTORY|O_NOFOLLOW) = 3
fstat(3, {st_mode=S_IFDIR|0777, st_size=21, ...}) = 0
fcntl(3, F_GETFL) = 0x38800 (flags O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_NOFOLLOW)
fcntl(3, F_SETFD, FD_CLOEXEC) = 0
getdents(3, /* 3 entries */, 32768) = 80
close(3) = 0
geteuid() = 1000
To conclude even if you own a directory and it has the executable bit, you still need read permissions so that you may see its contents and delete the folder. It's not the same for a file though.
Kind regards,
Taran.
New contributor
edited 10 hours ago
New contributor
answered 10 hours ago
ttaran7ttaran7
313
313
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f502659%2fwhy-is-rm-r-unable-to-delete-this-folder%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown