LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 03-23-2013, 10:34 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
chmod -w john.c'. Then 'rm *' deletes john.c too!


Hi: Suppose I want to delete all files in a directory except one, john.c. What I did was to reset the write bit in the permissions, 'chmod -w john.c'. Then 'rm *'. But john.c got deleted too. Any way out of this?
 
Old 03-23-2013, 10:40 PM   #2
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
did you rm * as john.c the user or what ever user has permissions to write to those files?
 
Old 03-23-2013, 10:45 PM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
File owner can do this. It seems that you're the owner of the file.

So first change the ownership of the file, remove write permissions and then try to remove all other files.

Code:
~$ chown user:group john.c
~$ chmod 550 john.c
~$ rm -rf ./*
BEWARE: Be alert when you run rm -rf ./* command, and make sure that you're in correct directory.
 
1 members found this post helpful.
Old 03-23-2013, 10:54 PM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Deleting john.c is possible because you hold write permissions on the directory. The proposal to change ownership of the file seems to be correct to me.

jlinkels
 
1 members found this post helpful.
Old 03-23-2013, 10:58 PM   #5
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Useful answers. They will be saved. Thanks.
 
Old 03-23-2013, 11:12 PM   #6
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Removing a file is an operation on the directory, so the directory permissions are what matters. If you have write permission in the directory, you can remove any file**. Write permission for the file is not required, but if you try to remove a file for which you do not have write permission, the rm command will, in the absence of the "-f" flag and if stdin is connected to a terminal, ask for confirmation before doing the removal. But that is really just a warning, and you do have the permission needed to remove the file.
**Directories with the "sticky" bit set in their permissions ("t" in the last character of the ASCII permissions) have an additional restriction. To remove a file from such a directory you must be the owner of the file or the owner of the directory. This bit is commonly set on publicly writeable directories like /tmp (perms "rwxrwxrwt").
 
Old 03-23-2013, 11:18 PM   #7
harryhaller
Member
 
Registered: Sep 2004
Distribution: Slackware-14.2
Posts: 468

Rep: Reputation: Disabled
It should stop and ask you before deleting the file.
Quote:
rm: remove write-protected regular file ‘/path/file.1’?
If the directory is also no-write, it'll ignore a 'y' response and refuse to delete the others as well.
Quote:
rm: remove write-protected regular file ‘/home/sysout/test.w/r.1’? y
rm: cannot remove ‘/path/file.1’: Permission denied
rm: cannot remove ‘/path/file.2’: Permission denied
rm: cannot remove ‘/path/file.3’: Permission denied
 
  


Reply



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
My name is John and I am new here kinetic1001101 LinuxQuestions.org Member Intro 1 09-20-2010 12:33 PM
[SOLVED] Is John on line? stf92 LQ Suggestions & Feedback 12 08-17-2010 04:48 AM
My name is John and I'm a Linuxholic pushback LinuxQuestions.org Member Intro 2 12-07-2008 11:05 PM
John Lumby John Lumby LinuxQuestions.org Member Intro 2 10-22-2008 10:31 AM
John The Ripper infinity0022 Linux - Security 1 02-24-2008 12:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:39 PM.

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
Open Source Consulting | Domain Registration