# recursive chmod?



## Anonymous (Nov 21, 2010)

I accidentally did an install world onto a directory in my / slice because I was trying to make a jail but I realized I should have put it on /usr. Once I realized this I tried deleting/moving it but a ton of the files have the sticky bit set. Is there an easy way to recursively go through the directories and turn the sticky bit off so I can delete those files?


----------



## Terry_Kennedy (Nov 21, 2010)

mharvey87 said:
			
		

> I tried deleting/moving it but a ton of the files have the sticky bit set. Is there an easy way to recursively go through the directories and turn the sticky bit off so I can delete those files?


Do you mean the immutable flag? I don't think the sticky bit would affect deleting the files as long as you're root at the time. From sticky():

_A file in a sticky directory may only be removed or renamed by a user if the user has write permission for the directory and the user is the owner of the file, the owner of the directory, or the super-user._

As an example:


```
(0:16) new-gate:/# find -x . -flags +schg -exec ls -lo {} \;
-r-sr-xr-x  1 root  wheel  schg 20400 Nov 20 19:47 ./bin/rcp
-r--r--r--  1 root  wheel  schg 1289912 Nov 20 19:47 ./lib/libc.so.7
-r--r--r--  1 root  wheel  schg 33744 Nov 20 19:47 ./lib/libcrypt.so.5
-r--r--r--  1 root  wheel  schg 93328 Nov 20 19:47 ./lib/libthr.so.3
-r-xr-xr-x  1 root  wheel  schg 246184 Nov 20 19:47 ./libexec/ld-elf.so.1
-r-xr-xr-x  1 root  wheel  schg 220012 Nov 20 19:48 ./libexec/ld-elf32.so.1
-r-xr-xr-x  1 root  wheel  schg 745240 Nov 20 19:47 ./sbin/init
```

This causes files on the current mount point (the -x option keeps find from descending into other mount points) with the schg flag set to have their flags listed (the "ls -lo" part). Once you find the files in question, you can either manually use `# chflags` to reset the flags, or you can replace the "ls -lo" part with the appropriate command. For example (not tested!) `# find -x . -flags +schg -exec chflags noschg {} \;`You need to be in single-user mode to reset the flags to allow deletion of the file. See security() (search for securelevel) for details on security levels.

On the other hand, if I completely missed your point, ignore what I said and post a clarification...


----------



## Anonymous (Nov 21, 2010)

Yeah I just got the immutable flag and sticky bit mixed up. Ended up solving the problem by "chflags -R"


----------

