How to delete read only files.

Ngie Cooper yaneurabeya at gmail.com
Tue Jan 31 01:53:55 UTC 2017


> On Jan 30, 2017, at 16:19, Ian Lepore <ian at freebsd.org> wrote:
> 
>> On Mon, 2017-01-30 at 16:12 -0800, Balaji Palaniswami wrote:
>> Hi,
>> 
>> I am trying to delete read only files.
>> 
>> # pwd
>> /usr/home/bp/nfsroot/lib
>> # whoami
>> root
>> # ls
>> libc.so.7       libcrypt.so.5   libthr.so.3
>> # ls -ltr
>> total 3264
>> -r--r--r--  1 root  wheel  1460592 Jan 29 12:07 libc.so.7
>> -r--r--r--  1 root  wheel    51640 Jan 29 12:07 libcrypt.so.5
>> -r--r--r--  1 root  wheel   109568 Jan 29 12:08 libthr.so.3
>> # rm -rf libc.so.7
>> rm: libc.so.7: Operation not permitted
>> 
>> # chmod 777 libc.so.7
>> chmod: libc.so.7: Operation not permitted
>> 
>> Please suggest me some ways to delete these files.
>> 
>> Thanks,
>> Balaji
> 
> Those libraries typically have the 'schg' flag set on them, as do some
> others in the tree.  If you need to wipe everything under nfsroot, the
> typical incantation is
> 
>   rm -rf nfsroot/ ; chflags -R noschg nfsroot/; rm -rf nfsroot/
> 
> that deletes everything it can first, then changes the flags on what's
> left, then deletes them too.  (Doing the noschg first requires
> examining/changing 145,000 files.)

chflags -R 0 covers the nouchg case as well.

Cheers,
-Ngie


More information about the freebsd-hackers mailing list