-2

From coreutils manual

2.10 Traversing symlinks

The following options modify how chown and chgrp traverse a hierarchy when the --recursive (-R) option is also specified. If more than one of the following options is specified, only the final one takes effect. These options specify whether processing a symbolic link to a directory entails operating on just the symbolic link or on all files in the hierarchy rooted at that directory.

These options are independent of --dereference and --no-dereference (-h), which control whether to modify a symlink or its referent.

-H If --recursive (-R) is specified and a command line argument is a symbolic link to a directory, traverse it.

-L In a recursive traversal, traverse every symbolic link to a directory that is encountered.

-P Do not traverse any symbolic links. This is the default if none of -H, -L, or -P is specified.

  1. In "These options are independent of --dereference and --no-dereference (-h), which control whether to modify a symlink or its referent", what do "these options" and "--dereference and --no-dereference" do respectively, and how are they different?

  2. The descriptions for -H and for -L seem to say the same thing to me. How are these two options different?

Thanks.

  • 2
    i think you want we-read-man-pages-for-you.stackexchange.com – cas Jul 3 '16 at 16:32
  • I think you don't need to read my posts if you don't like – Tim Jul 3 '16 at 16:36
  • 2
    By the time I realise it's another one of your "read this man page for me" or "explain the bleeding obvious to me" questions, it's too late - I've already wasted my time reading it. It wouldn't be so bad if you showed any sign of ever learning from the detailed answers people give you, but you don't. If you get a good answer, your most common response is to immediately post a trivial and extremely obvious variation of the same question. – cas Jul 3 '16 at 16:41
  • I don't understand your comment. sorry. – Tim Jul 3 '16 at 16:43
  • 2
    That's the trouble. you seem to have no capacity to think about or understand anything. Your first instinct on seeing something you don't understand (which is almost everything, AFAICT) is NOT to think about it or apply previously learned knowledge or experiment and find out, it's to ask someone else to tell you. Answering you is a waste of time because it never sinks in. – cas Jul 3 '16 at 16:46
1

The -h flag (aka --no-dereference) is a good flag to use. Let's say we have this setup:

$ ln -s /etc/passwd /tmp/foobar
$ sudo chown fred /tmp/foobar

Because --dereference is the default, this will actually change /etc/passwd... which is probably not what you want :-) The -h flag would make it change the symlink ownership instead. So you should get into the habit of using -h, especially if recursively changing ownership. i.e. do chmod -hR rather than chmod -R.

The -H flag only applies to directory symlinks you list on the command line. The -L option applies to all directory symlinks found, including those in subdirectories during a recursive chown.

  • thanks. 1) Does "The following options modify how chown and chgrp traverse a hierarchy when the --recursive (-R) option is also specified" mean that -H, -L, and -P are always used together with -R? 2) Does "-P Do not traverse any symbolic links" imply that -P is not used with -R? – Tim Jul 3 '16 at 14:55
  • -P is the default; symlinks to directories are not followed for recursion. You need to specify -H or -L to recurse into them. This is a perfect case where you can build test trees and experiment. – Stephen Harris Jul 3 '16 at 14:59
  • (1) Does using -P, -H, or -L make sense only when -R is used? (2) What do test trees and experiment mean? – Tim Jul 3 '16 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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