Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Say I have a symlink:

linktob -> b

If I run something like find . -type l -execdir chmod 777 {} \;, the chmod command affects the file the symlink is pointing to, i.e. ‘b’.

The man page suggests that symlinks aren’t followed by default, but that doesn’t seem to be the case here.

How can I get -execdir, -exec etc. to work on the symlink itself?

share|improve this question

1 Answer 1

You can see from this example that the find command does actually operate on the symlink:

$ ls -l *
subdir1:
total 0
-rwxrwxrwx 1 nate nate 0 Jun 13 09:20 realfile

subdir2:
total 0
lrwxrwxrwx 1 nate nate 19 Jun 13 09:20 symlinkfile -> ../subdir1/realfile
$ find . -type l -exec ls "{}" \;
./subdir2/symlinkfile

But the underlying command (e.g. chmod) might not. In this example, we can see that chmod is actually changing the permissions of the target file:

$ find . -type l -exec chmod -v 777 "{}" \;
mode of `./subdir2/symlinkfile' retained as 0777 (rwxrwxrwx)
$ find . -type l -exec chmod -v 444 "{}" \;
mode of `./subdir2/symlinkfile' changed from 0777 (rwxrwxrwx) to 0444 (r--r--r--)

$ ls -l *
subdir1:
total 0
-r--r--r-- 1 nate nate 0 Jun 13 09:20 realfile

subdir2:
total 0
lrwxrwxrwx 1 nate nate 19 Jun 13 09:20 symlinkfile -> ../subdir1/realfile

from the chmod man page:

chmod never changes the permissions of symbolic links; the chmod system call cannot change their permissions

What are you trying to do to the symlink, exactly?

share|improve this answer
    
Thanks, I didn’t realise that. The same is also true of chgrp and chown. Using -h (where supported) on these commands affects the symlink itself, but seems pointless other than to cause an error message in ls if you take off read privilege. I’m in the process of tidying up permissions after we moved servers and the data was transferred over with silly permissions/user/group. I’ll need to make sure the find command only finds actual files and dirs otherwise I could end up changing settings in places like /usr or even /… –  user5817 Jun 14 '13 at 7:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.