Wednesday, April 21, 2010

Changing permissions in Linux

Have you ever needed to change permissions on directories (or files) in Linux, but sometimes need to only do it for a certain set? There are a bunch of different tricks to get the job done.

Take as a simple example, wanting to change permissions on all directories so that any future files created under them will have this permission. If you wanted to preserve the files as is, but put what is called a sticky bit onto the directories for all future files, do the following:
$ find -type d | xargs chmod g+s

The left side of the pipe lists all directories from where you are. The right side of the pipe will set the group bit permissions on all dirs in the find list on the left side of the pipe. The group bit will force all files created in those directories from now on to be owned by the user creating it and by the group of the parent directory.

How about if you wanted to find out which file/folders are NOT owned by a certain group (perhaps to change their ownership or permissions)?
find ! -group <name_of_group>

This will list all files/folders that are NOT owned by the group mentioned. You can then put that into a pipe to change ownership or permissions as shown above.

No comments:

Post a Comment