Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleting files except root and under /backup

Status
Not open for further replies.

slok

Programmer
Jul 2, 1999
108
SG
how can I delete files except those own by root
and under the /backup directory
 
One thing you could try is to set those files immutable using the chattr command. You would be unable to remove (or alter in any way) the file until you unset this tag.

Or you could go do something like:

find /[!b]* ! -user root -a ! -group root -exec rm -f {} \;

This will ignore anything in /boot or /bin, but anything in there should be owned by root anyway. Before you execute that command, you should be sure you're getting what you want, so try:

find /[!b]* ! -user root -a ! -group root -exec ls -l {} \;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top