0

In the case where the user home directory contains one or more NFS mount points, how can I skip these mounts and efficiently change directory permissions?

I want to run chmod o-rwx on all non-mounted directories under a user's home directory.

I will be running the command as the root user because I'm doing this for all users on the system. (The NFS mounts have the root_squash mount option.)

Here is what I tried. However, it is not working as expected.

sudo find /home/myuser/ -mount -path ./Documents -prune -o -type d -exec chmod o-rwx {} \; chmod: changing permissions of '/home/myuser/Documents': Operation not permitted 

I want to avoid the error message. More importantly, the find command is taking a very long time to run. I believe that indicates it is descending into the mount points (which contain many directories and files).

Another problem with my command is that I have to explicitly code for the locations to skip. All users have Documents mounted, but some users have other NFS mounts of different names.

My goal is to automate the fixing of simple directory permission problems in a user account (i.e., chmod o-rwx). How can I do this in my situation?

7
  • gnu.org/software/findutils/manual/html_mono/… Commented Feb 13, 2020 at 4:39
  • @muru - I am already using the -mount option. Is that what you were suggesting? All you did was post a link, so I don't know what you intended me to see there. Commented Feb 13, 2020 at 4:41
  • -mount should be doing what you wanted, and the error listed is because Documents is itself is a mountpoint. Are you sure that it's actually descending into the mountpoints? You could run an echo instead of the chmod to check for certain. Commented Feb 13, 2020 at 4:44
  • You are using it, -mount prevents descending into mounted directories, so it will only exclude contents of Documents, not Documents itself. Commented Feb 13, 2020 at 4:44
  • 1
    I think the problem with your prune is that it's trying to match ./Documents literally against the full path including the base you provided (/home/myuser/Documents). To do it on a larger scale you probably need to change the -path argument to */Documents or /home/*/Documents. Commented Feb 13, 2020 at 4:57

1 Answer 1

0

Here is the solution I came up with:

find /home/$theuser -mount -maxdepth 1 ! -fstype nfs4 ! -fstype nfs -type d -exec chmod o-rwx {} \; 

The negated fstype options solved one or two of my problems. The -maxdepth 1 solved the other (speed).

It may be possible to combine the two -fstype options. If anyone knows, please edit this answer.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.