Suppose you have permission to write to a file but not to delete it - What rights do we talk about?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
3
down vote

favorite
1












Suppose you have permission to write to a file but not to delete it.



What rights do we talk about?



Read and write rights?







share|improve this question
















  • 2




    Not sure what you're talking about, but askubuntu.com/questions/240424/…
    – muru
    May 21 at 7:45






  • 1




    Reopen voters: I think it's clear what OP is asking but wording could be better. Judging from answer up-votes it's a good question but might be a duplicate as Muru alludes.
    – WinEunuuchs2Unix
    May 22 at 13:02














up vote
3
down vote

favorite
1












Suppose you have permission to write to a file but not to delete it.



What rights do we talk about?



Read and write rights?







share|improve this question
















  • 2




    Not sure what you're talking about, but askubuntu.com/questions/240424/…
    – muru
    May 21 at 7:45






  • 1




    Reopen voters: I think it's clear what OP is asking but wording could be better. Judging from answer up-votes it's a good question but might be a duplicate as Muru alludes.
    – WinEunuuchs2Unix
    May 22 at 13:02












up vote
3
down vote

favorite
1









up vote
3
down vote

favorite
1






1





Suppose you have permission to write to a file but not to delete it.



What rights do we talk about?



Read and write rights?







share|improve this question












Suppose you have permission to write to a file but not to delete it.



What rights do we talk about?



Read and write rights?









share|improve this question











share|improve this question




share|improve this question










asked May 21 at 7:36







user831837














  • 2




    Not sure what you're talking about, but askubuntu.com/questions/240424/…
    – muru
    May 21 at 7:45






  • 1




    Reopen voters: I think it's clear what OP is asking but wording could be better. Judging from answer up-votes it's a good question but might be a duplicate as Muru alludes.
    – WinEunuuchs2Unix
    May 22 at 13:02












  • 2




    Not sure what you're talking about, but askubuntu.com/questions/240424/…
    – muru
    May 21 at 7:45






  • 1




    Reopen voters: I think it's clear what OP is asking but wording could be better. Judging from answer up-votes it's a good question but might be a duplicate as Muru alludes.
    – WinEunuuchs2Unix
    May 22 at 13:02







2




2




Not sure what you're talking about, but askubuntu.com/questions/240424/…
– muru
May 21 at 7:45




Not sure what you're talking about, but askubuntu.com/questions/240424/…
– muru
May 21 at 7:45




1




1




Reopen voters: I think it's clear what OP is asking but wording could be better. Judging from answer up-votes it's a good question but might be a duplicate as Muru alludes.
– WinEunuuchs2Unix
May 22 at 13:02




Reopen voters: I think it's clear what OP is asking but wording could be better. Judging from answer up-votes it's a good question but might be a duplicate as Muru alludes.
– WinEunuuchs2Unix
May 22 at 13:02










2 Answers
2






active

oldest

votes

















up vote
14
down vote



accepted










To write to an existing file you need write permissions for that file.



To delete a file you need write permission for the folder that contains that file.






share|improve this answer
















  • 2




    As an aside: rm asks first when one tries to delete a write protected file, even when the directory permissions are sufficient.
    – Peter A. Schneider
    May 21 at 13:47










  • As another aside, you can force write to a file itself if you have write permission on the directory - for example in Vim you can use :w!
    – Zanna
    May 22 at 14:42

















up vote
4
down vote













Florian's answer is not quite complete on my system: I need both write and execute permission on the directory in order to delete a file in it.



Sample session:



I'm running a well-seasoned Debian with the ext4 file system. I create a directory with a file in it and then change the directory and file permissions before I try to delete the file.



File system ext4:



testuser@www:~$ df -T .
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda3 ext4 152326340 44429904 100196624 31% /


Let's create a directory and a file in it:



testuser@www:~$ mkdir d
testuser@www:~$ ls -ld d
drwxr-xr-x 2 testuser testuser 4096 May 21 16:19 d
testuser@www:~$ echo kjhkjh > d/f
testuser@www:~$ ls -l d/f
-rw-r--r-- 1 testuser testuser 7 May 21 16:19 d/f


Expected: Cannot change file catalog without write permission on it:



testuser@www:~$ chmod 100 d && ls -ld d
d--x------ 2 testuser testuser 4096 May 21 16:19 d
testuser@www:~$ rm d/f
rm: cannot remove 'd/f': Permission denied


Unexpected: Cannot change file catalog without execute permission on it:



testuser@www:~$ chmod 200 d && ls -ld d
d-w------- 2 testuser testuser 4096 May 21 16:19 d
testuser@www:~$ rm d/f
rm: cannot remove 'd/f': Permission denied


I need both write and execute permission on it:



testuser@www:~$ chmod 300 d && ls -ld d
d-wx------ 2 testuser testuser 4096 May 21 16:19 d
testuser@www:~$ rm d/f


As an aside: When the file (but not the directory) is write protected rm asks for permission before deleting. After all, deleting a file can be considered an extreme form of writing to it. There is no difference in lost data between echo -n "" > d/f and rm d/f in the common case that there is no other hardlink to the file.



testuser@www:~$ !echo
echo kjhkjh > d/f
testuser@www:~$ chmod 700 d && ls -ld d
drwx------ 2 testuser testuser 4096 May 21 16:21 d
testuser@www:~$ chmod 000 d/f && ls -l d/f
---------- 1 testuser testuser 7 May 21 16:21 d/f
testuser@www:~$ rm d/f
rm: remove write-protected regular file 'd/f'? y
testuser@www:~$ ls -l d
total 0
testuser@www:~$





share|improve this answer




















  • I think one always needs execute/traversal permission on a directory and all its parents to do anything with its content in addition to read or write permissions.
    – David Foerster
    May 22 at 19:19











  • @DavidFoerster Well, that's usually not mentioned; neither in the accepted answer here nor in most other places. And it was new to me. The execute bit on directories is rarely well explained (do you have a canonical documentation? I couldn't find any within the 2 minutes I gave it). I't also only medium logical, I find. It also seems redundant: What can I then do with just write but not execute permission?
    – Peter A. Schneider
    May 23 at 0:38










  • Nothing. In a way the traversal permission (i. e. the execute flag on directories) effectively affects the children and grand-children and not the directory with that permission itself. See askubuntu.com/q/862289/175814 and the links in its comments for further reading.
    – David Foerster
    May 23 at 10:08










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
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',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1038595%2fsuppose-you-have-permission-to-write-to-a-file-but-not-to-delete-it-what-right%23new-answer', 'question_page');

);

Post as a guest





























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
14
down vote



accepted










To write to an existing file you need write permissions for that file.



To delete a file you need write permission for the folder that contains that file.






share|improve this answer
















  • 2




    As an aside: rm asks first when one tries to delete a write protected file, even when the directory permissions are sufficient.
    – Peter A. Schneider
    May 21 at 13:47










  • As another aside, you can force write to a file itself if you have write permission on the directory - for example in Vim you can use :w!
    – Zanna
    May 22 at 14:42














up vote
14
down vote



accepted










To write to an existing file you need write permissions for that file.



To delete a file you need write permission for the folder that contains that file.






share|improve this answer
















  • 2




    As an aside: rm asks first when one tries to delete a write protected file, even when the directory permissions are sufficient.
    – Peter A. Schneider
    May 21 at 13:47










  • As another aside, you can force write to a file itself if you have write permission on the directory - for example in Vim you can use :w!
    – Zanna
    May 22 at 14:42












up vote
14
down vote



accepted







up vote
14
down vote



accepted






To write to an existing file you need write permissions for that file.



To delete a file you need write permission for the folder that contains that file.






share|improve this answer












To write to an existing file you need write permissions for that file.



To delete a file you need write permission for the folder that contains that file.







share|improve this answer












share|improve this answer



share|improve this answer










answered May 21 at 7:42









Florian Diesch

62.4k16156176




62.4k16156176







  • 2




    As an aside: rm asks first when one tries to delete a write protected file, even when the directory permissions are sufficient.
    – Peter A. Schneider
    May 21 at 13:47










  • As another aside, you can force write to a file itself if you have write permission on the directory - for example in Vim you can use :w!
    – Zanna
    May 22 at 14:42












  • 2




    As an aside: rm asks first when one tries to delete a write protected file, even when the directory permissions are sufficient.
    – Peter A. Schneider
    May 21 at 13:47










  • As another aside, you can force write to a file itself if you have write permission on the directory - for example in Vim you can use :w!
    – Zanna
    May 22 at 14:42







2




2




As an aside: rm asks first when one tries to delete a write protected file, even when the directory permissions are sufficient.
– Peter A. Schneider
May 21 at 13:47




As an aside: rm asks first when one tries to delete a write protected file, even when the directory permissions are sufficient.
– Peter A. Schneider
May 21 at 13:47












As another aside, you can force write to a file itself if you have write permission on the directory - for example in Vim you can use :w!
– Zanna
May 22 at 14:42




As another aside, you can force write to a file itself if you have write permission on the directory - for example in Vim you can use :w!
– Zanna
May 22 at 14:42












up vote
4
down vote













Florian's answer is not quite complete on my system: I need both write and execute permission on the directory in order to delete a file in it.



Sample session:



I'm running a well-seasoned Debian with the ext4 file system. I create a directory with a file in it and then change the directory and file permissions before I try to delete the file.



File system ext4:



testuser@www:~$ df -T .
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda3 ext4 152326340 44429904 100196624 31% /


Let's create a directory and a file in it:



testuser@www:~$ mkdir d
testuser@www:~$ ls -ld d
drwxr-xr-x 2 testuser testuser 4096 May 21 16:19 d
testuser@www:~$ echo kjhkjh > d/f
testuser@www:~$ ls -l d/f
-rw-r--r-- 1 testuser testuser 7 May 21 16:19 d/f


Expected: Cannot change file catalog without write permission on it:



testuser@www:~$ chmod 100 d && ls -ld d
d--x------ 2 testuser testuser 4096 May 21 16:19 d
testuser@www:~$ rm d/f
rm: cannot remove 'd/f': Permission denied


Unexpected: Cannot change file catalog without execute permission on it:



testuser@www:~$ chmod 200 d && ls -ld d
d-w------- 2 testuser testuser 4096 May 21 16:19 d
testuser@www:~$ rm d/f
rm: cannot remove 'd/f': Permission denied


I need both write and execute permission on it:



testuser@www:~$ chmod 300 d && ls -ld d
d-wx------ 2 testuser testuser 4096 May 21 16:19 d
testuser@www:~$ rm d/f


As an aside: When the file (but not the directory) is write protected rm asks for permission before deleting. After all, deleting a file can be considered an extreme form of writing to it. There is no difference in lost data between echo -n "" > d/f and rm d/f in the common case that there is no other hardlink to the file.



testuser@www:~$ !echo
echo kjhkjh > d/f
testuser@www:~$ chmod 700 d && ls -ld d
drwx------ 2 testuser testuser 4096 May 21 16:21 d
testuser@www:~$ chmod 000 d/f && ls -l d/f
---------- 1 testuser testuser 7 May 21 16:21 d/f
testuser@www:~$ rm d/f
rm: remove write-protected regular file 'd/f'? y
testuser@www:~$ ls -l d
total 0
testuser@www:~$





share|improve this answer




















  • I think one always needs execute/traversal permission on a directory and all its parents to do anything with its content in addition to read or write permissions.
    – David Foerster
    May 22 at 19:19











  • @DavidFoerster Well, that's usually not mentioned; neither in the accepted answer here nor in most other places. And it was new to me. The execute bit on directories is rarely well explained (do you have a canonical documentation? I couldn't find any within the 2 minutes I gave it). I't also only medium logical, I find. It also seems redundant: What can I then do with just write but not execute permission?
    – Peter A. Schneider
    May 23 at 0:38










  • Nothing. In a way the traversal permission (i. e. the execute flag on directories) effectively affects the children and grand-children and not the directory with that permission itself. See askubuntu.com/q/862289/175814 and the links in its comments for further reading.
    – David Foerster
    May 23 at 10:08














up vote
4
down vote













Florian's answer is not quite complete on my system: I need both write and execute permission on the directory in order to delete a file in it.



Sample session:



I'm running a well-seasoned Debian with the ext4 file system. I create a directory with a file in it and then change the directory and file permissions before I try to delete the file.



File system ext4:



testuser@www:~$ df -T .
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda3 ext4 152326340 44429904 100196624 31% /


Let's create a directory and a file in it:



testuser@www:~$ mkdir d
testuser@www:~$ ls -ld d
drwxr-xr-x 2 testuser testuser 4096 May 21 16:19 d
testuser@www:~$ echo kjhkjh > d/f
testuser@www:~$ ls -l d/f
-rw-r--r-- 1 testuser testuser 7 May 21 16:19 d/f


Expected: Cannot change file catalog without write permission on it:



testuser@www:~$ chmod 100 d && ls -ld d
d--x------ 2 testuser testuser 4096 May 21 16:19 d
testuser@www:~$ rm d/f
rm: cannot remove 'd/f': Permission denied


Unexpected: Cannot change file catalog without execute permission on it:



testuser@www:~$ chmod 200 d && ls -ld d
d-w------- 2 testuser testuser 4096 May 21 16:19 d
testuser@www:~$ rm d/f
rm: cannot remove 'd/f': Permission denied


I need both write and execute permission on it:



testuser@www:~$ chmod 300 d && ls -ld d
d-wx------ 2 testuser testuser 4096 May 21 16:19 d
testuser@www:~$ rm d/f


As an aside: When the file (but not the directory) is write protected rm asks for permission before deleting. After all, deleting a file can be considered an extreme form of writing to it. There is no difference in lost data between echo -n "" > d/f and rm d/f in the common case that there is no other hardlink to the file.



testuser@www:~$ !echo
echo kjhkjh > d/f
testuser@www:~$ chmod 700 d && ls -ld d
drwx------ 2 testuser testuser 4096 May 21 16:21 d
testuser@www:~$ chmod 000 d/f && ls -l d/f
---------- 1 testuser testuser 7 May 21 16:21 d/f
testuser@www:~$ rm d/f
rm: remove write-protected regular file 'd/f'? y
testuser@www:~$ ls -l d
total 0
testuser@www:~$





share|improve this answer




















  • I think one always needs execute/traversal permission on a directory and all its parents to do anything with its content in addition to read or write permissions.
    – David Foerster
    May 22 at 19:19











  • @DavidFoerster Well, that's usually not mentioned; neither in the accepted answer here nor in most other places. And it was new to me. The execute bit on directories is rarely well explained (do you have a canonical documentation? I couldn't find any within the 2 minutes I gave it). I't also only medium logical, I find. It also seems redundant: What can I then do with just write but not execute permission?
    – Peter A. Schneider
    May 23 at 0:38










  • Nothing. In a way the traversal permission (i. e. the execute flag on directories) effectively affects the children and grand-children and not the directory with that permission itself. See askubuntu.com/q/862289/175814 and the links in its comments for further reading.
    – David Foerster
    May 23 at 10:08












up vote
4
down vote










up vote
4
down vote









Florian's answer is not quite complete on my system: I need both write and execute permission on the directory in order to delete a file in it.



Sample session:



I'm running a well-seasoned Debian with the ext4 file system. I create a directory with a file in it and then change the directory and file permissions before I try to delete the file.



File system ext4:



testuser@www:~$ df -T .
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda3 ext4 152326340 44429904 100196624 31% /


Let's create a directory and a file in it:



testuser@www:~$ mkdir d
testuser@www:~$ ls -ld d
drwxr-xr-x 2 testuser testuser 4096 May 21 16:19 d
testuser@www:~$ echo kjhkjh > d/f
testuser@www:~$ ls -l d/f
-rw-r--r-- 1 testuser testuser 7 May 21 16:19 d/f


Expected: Cannot change file catalog without write permission on it:



testuser@www:~$ chmod 100 d && ls -ld d
d--x------ 2 testuser testuser 4096 May 21 16:19 d
testuser@www:~$ rm d/f
rm: cannot remove 'd/f': Permission denied


Unexpected: Cannot change file catalog without execute permission on it:



testuser@www:~$ chmod 200 d && ls -ld d
d-w------- 2 testuser testuser 4096 May 21 16:19 d
testuser@www:~$ rm d/f
rm: cannot remove 'd/f': Permission denied


I need both write and execute permission on it:



testuser@www:~$ chmod 300 d && ls -ld d
d-wx------ 2 testuser testuser 4096 May 21 16:19 d
testuser@www:~$ rm d/f


As an aside: When the file (but not the directory) is write protected rm asks for permission before deleting. After all, deleting a file can be considered an extreme form of writing to it. There is no difference in lost data between echo -n "" > d/f and rm d/f in the common case that there is no other hardlink to the file.



testuser@www:~$ !echo
echo kjhkjh > d/f
testuser@www:~$ chmod 700 d && ls -ld d
drwx------ 2 testuser testuser 4096 May 21 16:21 d
testuser@www:~$ chmod 000 d/f && ls -l d/f
---------- 1 testuser testuser 7 May 21 16:21 d/f
testuser@www:~$ rm d/f
rm: remove write-protected regular file 'd/f'? y
testuser@www:~$ ls -l d
total 0
testuser@www:~$





share|improve this answer












Florian's answer is not quite complete on my system: I need both write and execute permission on the directory in order to delete a file in it.



Sample session:



I'm running a well-seasoned Debian with the ext4 file system. I create a directory with a file in it and then change the directory and file permissions before I try to delete the file.



File system ext4:



testuser@www:~$ df -T .
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda3 ext4 152326340 44429904 100196624 31% /


Let's create a directory and a file in it:



testuser@www:~$ mkdir d
testuser@www:~$ ls -ld d
drwxr-xr-x 2 testuser testuser 4096 May 21 16:19 d
testuser@www:~$ echo kjhkjh > d/f
testuser@www:~$ ls -l d/f
-rw-r--r-- 1 testuser testuser 7 May 21 16:19 d/f


Expected: Cannot change file catalog without write permission on it:



testuser@www:~$ chmod 100 d && ls -ld d
d--x------ 2 testuser testuser 4096 May 21 16:19 d
testuser@www:~$ rm d/f
rm: cannot remove 'd/f': Permission denied


Unexpected: Cannot change file catalog without execute permission on it:



testuser@www:~$ chmod 200 d && ls -ld d
d-w------- 2 testuser testuser 4096 May 21 16:19 d
testuser@www:~$ rm d/f
rm: cannot remove 'd/f': Permission denied


I need both write and execute permission on it:



testuser@www:~$ chmod 300 d && ls -ld d
d-wx------ 2 testuser testuser 4096 May 21 16:19 d
testuser@www:~$ rm d/f


As an aside: When the file (but not the directory) is write protected rm asks for permission before deleting. After all, deleting a file can be considered an extreme form of writing to it. There is no difference in lost data between echo -n "" > d/f and rm d/f in the common case that there is no other hardlink to the file.



testuser@www:~$ !echo
echo kjhkjh > d/f
testuser@www:~$ chmod 700 d && ls -ld d
drwx------ 2 testuser testuser 4096 May 21 16:21 d
testuser@www:~$ chmod 000 d/f && ls -l d/f
---------- 1 testuser testuser 7 May 21 16:21 d/f
testuser@www:~$ rm d/f
rm: remove write-protected regular file 'd/f'? y
testuser@www:~$ ls -l d
total 0
testuser@www:~$






share|improve this answer












share|improve this answer



share|improve this answer










answered May 21 at 14:40









Peter A. Schneider

1837




1837











  • I think one always needs execute/traversal permission on a directory and all its parents to do anything with its content in addition to read or write permissions.
    – David Foerster
    May 22 at 19:19











  • @DavidFoerster Well, that's usually not mentioned; neither in the accepted answer here nor in most other places. And it was new to me. The execute bit on directories is rarely well explained (do you have a canonical documentation? I couldn't find any within the 2 minutes I gave it). I't also only medium logical, I find. It also seems redundant: What can I then do with just write but not execute permission?
    – Peter A. Schneider
    May 23 at 0:38










  • Nothing. In a way the traversal permission (i. e. the execute flag on directories) effectively affects the children and grand-children and not the directory with that permission itself. See askubuntu.com/q/862289/175814 and the links in its comments for further reading.
    – David Foerster
    May 23 at 10:08
















  • I think one always needs execute/traversal permission on a directory and all its parents to do anything with its content in addition to read or write permissions.
    – David Foerster
    May 22 at 19:19











  • @DavidFoerster Well, that's usually not mentioned; neither in the accepted answer here nor in most other places. And it was new to me. The execute bit on directories is rarely well explained (do you have a canonical documentation? I couldn't find any within the 2 minutes I gave it). I't also only medium logical, I find. It also seems redundant: What can I then do with just write but not execute permission?
    – Peter A. Schneider
    May 23 at 0:38










  • Nothing. In a way the traversal permission (i. e. the execute flag on directories) effectively affects the children and grand-children and not the directory with that permission itself. See askubuntu.com/q/862289/175814 and the links in its comments for further reading.
    – David Foerster
    May 23 at 10:08















I think one always needs execute/traversal permission on a directory and all its parents to do anything with its content in addition to read or write permissions.
– David Foerster
May 22 at 19:19





I think one always needs execute/traversal permission on a directory and all its parents to do anything with its content in addition to read or write permissions.
– David Foerster
May 22 at 19:19













@DavidFoerster Well, that's usually not mentioned; neither in the accepted answer here nor in most other places. And it was new to me. The execute bit on directories is rarely well explained (do you have a canonical documentation? I couldn't find any within the 2 minutes I gave it). I't also only medium logical, I find. It also seems redundant: What can I then do with just write but not execute permission?
– Peter A. Schneider
May 23 at 0:38




@DavidFoerster Well, that's usually not mentioned; neither in the accepted answer here nor in most other places. And it was new to me. The execute bit on directories is rarely well explained (do you have a canonical documentation? I couldn't find any within the 2 minutes I gave it). I't also only medium logical, I find. It also seems redundant: What can I then do with just write but not execute permission?
– Peter A. Schneider
May 23 at 0:38












Nothing. In a way the traversal permission (i. e. the execute flag on directories) effectively affects the children and grand-children and not the directory with that permission itself. See askubuntu.com/q/862289/175814 and the links in its comments for further reading.
– David Foerster
May 23 at 10:08




Nothing. In a way the traversal permission (i. e. the execute flag on directories) effectively affects the children and grand-children and not the directory with that permission itself. See askubuntu.com/q/862289/175814 and the links in its comments for further reading.
– David Foerster
May 23 at 10:08












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1038595%2fsuppose-you-have-permission-to-write-to-a-file-but-not-to-delete-it-what-right%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Which professions warranted travel in Medieval times?

How do so many people here on Academia.SE, and in general, afford lavish higher education programs?

Trouble downloading packages list due to a “Hash sum mismatch” error