LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-06-2015, 09:51 AM   #1
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 536

Rep: Reputation: Disabled
remove write-protected regular file without permission


I wanted to delete a couple of files, so I did. Then I noticed that they were "write-protected". What does that mean? Why was I able to delete the files considering I wasn't the owner and the files did not have group write permission?

Code:
[Michael@devserver backup_database]$ ls -l
total 4344
-rw-r--r--. 1 apache apache   50639 Feb  6 05:42 2015_02_06_05_42_01.sql
-rw-r--r--. 1 apache apache  654623 Feb  6 05:45 2015_02_06_05_45_54.sql
-rw-r--r--. 1 apache apache 3738269 Feb  6 05:49 2015_02_06_05_49_02.sql
[Michael@devserver backup_database]$ rm *
rm: remove write-protected regular file `2015_02_06_05_42_01.sql'? y
rm: remove write-protected regular file `2015_02_06_05_45_54.sql'? y
rm: remove write-protected regular file `2015_02_06_05_49_02.sql'? y
[Michael@devserver backup_database]$ ls -l
total 0
[Michael@devserver backup_database]$
 
Old 02-06-2015, 10:43 AM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
You only need write access to the parent directory to create or delete files.
 
1 members found this post helpful.
Old 02-08-2015, 07:57 AM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,602

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
I know this is a bit late, but I thought a bit more information would help...

When a file is "deleted", what actually happens:

1. the entry in the directory is removed, and the directory rewritten (thus requiring write access to the directory).

2. the link count in the file inode is decremented

3. The filesystem supporting the file detects if the link count in the inode is zero (it requires the inode to be overwritten), and if the link count is 0, then the disk blocks of the file (and the metadata) are deallocated, and the inode returned to the free list for reuse.

Sometimes the sequence can be interrupted (power failures/etc). On non-journaling filesystems this will result in a "lost file" - and when an fsck pass is done, the inode is identified as not being in a directory. This situation is repaired by fsck by putting a file name in the "lost+found" file in the filesystems root directory. This rarely happens with a journaling filesystem as the mount will reprocess the journal and commit the outstanding transactions, thus repairing the filesystem.

Interrups can also occur before the data blocks are freed - thus getting errors of "free block not in free list". These are also easily repaired by fsck - it just puts them back in the free list.

Last edited by jpollard; 02-08-2015 at 08:16 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove Write-Protected File jaypas Linux - Newbie 1 07-30-2010 05:34 PM
File write protected without chattr??? abefroman Linux - Server 1 12-06-2008 07:12 AM
Cant remove write protected weird file tuxombie Slackware 13 12-07-2004 10:44 AM
Sharing a directory with a regular user (with write permission) Ironica Linux - Newbie 6 05-31-2004 12:27 PM
remove write-protected file randomtask Linux - Newbie 5 04-22-2004 04:06 AM


All times are GMT -5. The time now is 10:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration