Why “rm -r” is unable to delete this folder?I can not remove folder from serverAdding supllimentary group...
show notifications of new e-mails without displaying the content
How can I give a Ranger advantage on a check due to Favored Enemy without spoiling the story for the player?
Do the speed limit reductions due to pollution also apply to electric cars in France?
Protagonist constantly has to have long words explained to her. Will this get tedious?
How do I draw a function along with a particular tangent line at a specific point?
Why do single electrical receptacles exist?
If I tried and failed to start my own business, how do I apply for a job without job experience?
Homeostasis logic/math problem
How can changes in personality/values of a person who turned into a vampire be explained?
How do I avoid the "chosen hero" feeling?
Using Ansible, how can I take actions on each file in a specific location?
Can you say "leftside right"?
Is it possible to narrate a novel in a faux-historical style without alienating the reader?
Including proofs of known theorems in master's thesis
Why did Ylvis use "go" instead of "say" in phrases like "Dog goes 'woof'"?
Buying a "Used" Router
Are all power cords made equal?
How can I handle players killing my NPC outside of combat?
Tikz: Perpendicular FROM a line
Is there any danger of my neighbor having my wife's signature?
Minimum Viable Product for RTS game?
How can guns be countered by melee combat without raw-ability or exceptional explanations?
How can I prevent an oracle who can see into the past from knowing everything that has happened?
Lubuntu 18.10 File Manager: How to view directory tree structure?
Why “rm -r” is 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 the -wx
permissions called folder1
and another folder inside of it called folder2
with the rwx
permissions.
I have tried to delete folder1
using this command:
rm -r folder1
But I got the following error:
rm: cannot remove 'folder1': Permission denied
The reason why 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 those 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 the -wx
permissions called folder1
and another folder inside of it called folder2
with the rwx
permissions.
I have tried to delete folder1
using this command:
rm -r folder1
But I got the following error:
rm: cannot remove 'folder1': Permission denied
The reason why 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 those 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 the -wx
permissions called folder1
and another folder inside of it called folder2
with the rwx
permissions.
I have tried to delete folder1
using this command:
rm -r folder1
But I got the following error:
rm: cannot remove 'folder1': Permission denied
The reason why 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 those 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 the -wx
permissions called folder1
and another folder inside of it called folder2
with the rwx
permissions.
I have tried to delete folder1
using this command:
rm -r folder1
But I got the following error:
rm: cannot remove 'folder1': Permission denied
The reason why 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 those 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
asked 51 mins ago
JohnJohn
1486
1486
add a comment |
add a comment |
3 Answers
3
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.)
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
25 mins ago
add a comment |
First you need to have write and execute permission on the directory that your directory is located in.
'sudo' command should do the trick.
I generally tend to use rm -rf (f being force) to avoid prompts.
I think that's not a good habit.
– PRY
11 mins ago
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 |
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-rm-r-is-unable-to-delete-this-folder%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
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.)
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
25 mins ago
add a comment |
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.)
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
25 mins ago
add a comment |
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 27 mins ago
answered 44 mins ago
user2233709user2233709
903311
903311
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
25 mins ago
add a comment |
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
25 mins 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
25 mins 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
25 mins ago
add a comment |
First you need to have write and execute permission on the directory that your directory is located in.
'sudo' command should do the trick.
I generally tend to use rm -rf (f being force) to avoid prompts.
I think that's not a good habit.
– PRY
11 mins ago
add a comment |
First you need to have write and execute permission on the directory that your directory is located in.
'sudo' command should do the trick.
I generally tend to use rm -rf (f being force) to avoid prompts.
I think that's not a good habit.
– PRY
11 mins ago
add a comment |
First you need to have write and execute permission on the directory that your directory is located in.
'sudo' command should do the trick.
I generally tend to use rm -rf (f being force) to avoid prompts.
First you need to have write and execute permission on the directory that your directory is located in.
'sudo' command should do the trick.
I generally tend to use rm -rf (f being force) to avoid prompts.
answered 43 mins ago
TorofTorof
254
254
I think that's not a good habit.
– PRY
11 mins ago
add a comment |
I think that's not a good habit.
– PRY
11 mins ago
I think that's not a good habit.
– PRY
11 mins ago
I think that's not a good habit.
– PRY
11 mins ago
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
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 15 mins ago
New contributor
answered 21 mins ago
ttaran7ttaran7
12
12
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-rm-r-is-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