LinuxQuestions.org
Review your favorite Linux distribution.
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-17-2009, 11:56 AM   #1
laki47
Member
 
Registered: Feb 2009
Posts: 33

Rep: Reputation: 15
File/User permissions - how it can be deleted?


I have a question about file (and users!) permissions. When I log on as root and create i.e. ascii file test.txt in empty folder and then try ls -l I get next:

-rw-r--r-- 1 root root 13 2009-02-17 17:35 test.txt

Then I log as "normal" user i.e. jsmith and try following in the same directory:

rm test.txt

I get:

rm: remove write-protected regular file `test.txt'?

Typing y the file is gone!

Question -> How can I delete file whose owner is root???

Please help me, I am new one in this and thank you in advance!

Last edited by laki47; 02-17-2009 at 11:58 AM.
 
Old 02-17-2009, 12:04 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
"Write permission" refers to the ability to modify a file, not to create or destroy it. I believe it's the permissions of the containing directory that control that. What we call a "directory" is in reality more like a file containing a list of other files, so it's the write permissions on the "directory" file that affect what can exist inside it.
 
Old 02-17-2009, 12:08 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Good question! I think because the parent directory belong to the user and not to root. Deleting a file means to delete an entry in the file list of that directory (remember that even a directory is a file in linux) so you can modify a directory which belong to you. On the other hand you cannot append some text to that file, since you're going to modify the content of the file itself:
Code:
$ cat >> file.txt
bash: file.txt: Permission denied
Edit: Argghhh... too late!
 
Old 02-17-2009, 12:17 PM   #4
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,200

Rep: Reputation: 397Reputation: 397Reputation: 397Reputation: 397
not to sound rude but what you are describing is the whole point of permissions, so one person cant accidentally delete another user's files or access them without permission

back when i was in high school i took a c++ class at a community college on the side and to collect our homework since the instructor didnt have root access to the machine he would ftp to our home directories with our account credentials to get our homework
this is also the reason why it is best not to use the root account on linux for anything other then administration functions so a virus or hacker that takes over a task run with the priveleges of your user account can't delete critical system files

in answer to your query the best way to delete a file owned by root is to temporarily become root with su or sudo and delete the file

Last edited by frieza; 02-17-2009 at 12:24 PM.
 
Old 02-17-2009, 03:36 PM   #5
openSauce
Member
 
Registered: Oct 2007
Distribution: Fedora, openSUSE
Posts: 252

Rep: Reputation: 39
Quote:
Originally Posted by frieza View Post
not to sound rude but what you are describing is the whole point of permissions, so one person cant accidentally delete another user's files or access them without permission
Good job you didn't say that any ruder, because you completely misread his question
 
Old 02-18-2009, 06:14 PM   #6
servat78
Member
 
Registered: Jan 2009
Posts: 100

Rep: Reputation: 17
You need to be root to delete a file owned by root. If your user account is among the sudo users, then you can do it without actually logging in as root. Most often 'su -c rm file.txt' is used to run a single command with root privileges (needs password, of course).
Use 'chown' to change the owner or group of the file.
Use 'chmod' to change prmissions on the file.

Debian

Last edited by servat78; 02-19-2009 at 12:31 PM.
 
Old 02-19-2009, 01:49 AM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Quote:
Originally Posted by servat78 View Post
You need to be root to delete a file owned by root.
No you don't. Please read more carefully. That's the whole point of this thread. You just need to have permission to write to the directory the file sits in.
 
  


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
User file permissions tapanga Linux - Software 14 07-04-2008 12:36 AM
Lost Password file when user deleted clickit999 Linux - Security 2 09-19-2004 12:12 PM
user file permissions for windows partitions Alfanut Mandriva 6 04-27-2004 09:24 PM
file/user permissions? e1000 Linux - Newbie 3 11-14-2003 12:42 PM
root vs. user file permissions learning2fly Slackware 4 07-17-2003 01:06 PM


All times are GMT -5. The time now is 08:16 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