Score:0

Set file permissions, exclude folder - doesn't work with chmod (works with chown?)

de flag

I want to change file permissions and exclude a folder and it's contents (or only the contents is okay too).

It doesn't seem to work the same way as with chown - beause with chown I can change owner and exklude a folder like this:

sudo find . ! \( -path './images' -o -path './images/*' \)  -exec chown 33:33 {} \;

But when I try to change permissions with the same syntax:

sudo find . ! \( -path '/home/myuser/testdir/three/uploads/*' -o -path 
'/home/myuser/testdir/three/uploads' \) -type f -exec chmod 644 {} \;

That folder was not excluded, all files were affected. And it's not because of the added "-type f", that works with the chown command too.

So I'm wondering what I need to change to make it work with the chmod command?

Score:2
pt flag

This problem does not result from the chmod command but from your find expressions.

In your working example you tests like -path './images' that match the starting directory ., while in your non-working command you use absolute paths for -path with the same relative starting directory.

To see what files match your expressions, run

sudo find . ! \( -path '/home/myuser/testdir/three/uploads/*' -o -path 
'/home/myuser/testdir/three/uploads' \) -type f -print

I suggest to omit all exclude patterns first and then add exclude patterns that actually match the printed paths of the files.

In general, if you want to execute a command that will change something on your system, you should test the find command with -print first until you get the expected list of files before you add the -exec action.


Another option would be to use a matching start directory, e.g.

sudo find /home/myuser/testdir ! \( -path '/home/myuser/testdir/three/uploads/*' -o -path 
'/home/myuser/testdir/three/uploads' \) -type f -print
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.