<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: How to Lock a File for Renaming/Deleting in Linux	</title>
	<atom:link href="https://www.tecmint.com/prevent-file-deletion-linux/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.tecmint.com/prevent-file-deletion-linux/</link>
	<description>Tecmint - Linux Howtos, Tutorials, Guides, News, Tips and Tricks.</description>
	<lastBuildDate>Thu, 13 Feb 2025 04:08:13 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>
		By: Ravi Saive		</title>
		<link>https://www.tecmint.com/prevent-file-deletion-linux/comment-page-1/#comment-2270639</link>

		<dc:creator><![CDATA[Ravi Saive]]></dc:creator>
		<pubDate>Thu, 13 Feb 2025 04:08:13 +0000</pubDate>
		<guid isPermaLink="false">https://www.tecmint.com/?p=59543#comment-2270639</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.tecmint.com/prevent-file-deletion-linux/comment-page-1/#comment-2270540&quot;&gt;Peter Samuel&lt;/a&gt;.

@Peter,

You&#039;re absolutely right! Removing write permissions from a file (&lt;code&gt;chmod a-w file&lt;/code&gt;) does not prevent it from being deleted if the user has write permission on the parent directory.

To truly prevent deletion, the best approach is:

&lt;strong&gt;1.&lt;/strong&gt; Make the directory immutable, which will prevents any modifications, including file deletions inside the directory.
&lt;pre&gt;
chattr +i directory/
&lt;/pre&gt;
&lt;strong&gt;2.&lt;/strong&gt; Modify directory permissions.
&lt;pre&gt;
chmod a-w directory/
&lt;/pre&gt;
This removes write access, preventing users from deleting files.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a target="_blank" href="https://www.tecmint.com/prevent-file-deletion-linux/comment-page-1/#comment-2270540">Peter Samuel</a>.</p>
<p>@Peter,</p>
<p>You&#8217;re absolutely right! Removing write permissions from a file (<code>chmod a-w file</code>) does not prevent it from being deleted if the user has write permission on the parent directory.</p>
<p>To truly prevent deletion, the best approach is:</p>
<p><strong>1.</strong> Make the directory immutable, which will prevents any modifications, including file deletions inside the directory.</p>
<pre>
chattr +i directory/
</pre>
<p><strong>2.</strong> Modify directory permissions.</p>
<pre>
chmod a-w directory/
</pre>
<p>This removes write access, preventing users from deleting files.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Peter Samuel		</title>
		<link>https://www.tecmint.com/prevent-file-deletion-linux/comment-page-1/#comment-2270540</link>

		<dc:creator><![CDATA[Peter Samuel]]></dc:creator>
		<pubDate>Wed, 12 Feb 2025 20:17:21 +0000</pubDate>
		<guid isPermaLink="false">https://www.tecmint.com/?p=59543#comment-2270540</guid>

					<description><![CDATA[&quot;&lt;code&gt;chmod a-w file&lt;/code&gt;&quot; will NOT prevent it from being removed! The file can be removed if the user has write permission on the directory. You will/might see a warning asking if you wish to remove a write-protected file
&lt;pre&gt;
touch A
chmod a-w A
ls -l A

-r--r--r-- 1 psamuel psamuel 0 Feb 12 15:09 A
&lt;/pre&gt;
&lt;pre&gt;
rm A
rm: remove write-protected regular empty file &#039;A&#039;? y   # user types &#039;y&#039; followed by NEWLINE
ls -l A
/bin/ls: cannot access &#039;A&#039;: No such file or directory
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>&#8220;<code>chmod a-w file</code>&#8221; will NOT prevent it from being removed! The file can be removed if the user has write permission on the directory. You will/might see a warning asking if you wish to remove a write-protected file</p>
<pre>
touch A
chmod a-w A
ls -l A

-r--r--r-- 1 psamuel psamuel 0 Feb 12 15:09 A
</pre>
<pre>
rm A
rm: remove write-protected regular empty file 'A'? y   # user types 'y' followed by NEWLINE
ls -l A
/bin/ls: cannot access 'A': No such file or directory
</pre>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
