1*ba0aa175Smaxv.\" $NetBSD: symlink.7,v 1.29 2019/03/25 19:24:30 maxv Exp $ 2945fe691Sjdolecek.\" 3945fe691Sjdolecek.\" Copyright (c) 1992, 1993, 1994 4945fe691Sjdolecek.\" The Regents of the University of California. All rights reserved. 5945fe691Sjdolecek.\" 6945fe691Sjdolecek.\" Redistribution and use in source and binary forms, with or without 7945fe691Sjdolecek.\" modification, are permitted provided that the following conditions 8945fe691Sjdolecek.\" are met: 9945fe691Sjdolecek.\" 1. Redistributions of source code must retain the above copyright 10945fe691Sjdolecek.\" notice, this list of conditions and the following disclaimer. 11945fe691Sjdolecek.\" 2. Redistributions in binary form must reproduce the above copyright 12945fe691Sjdolecek.\" notice, this list of conditions and the following disclaimer in the 13945fe691Sjdolecek.\" documentation and/or other materials provided with the distribution. 14075022b3Sagc.\" 3. Neither the name of the University nor the names of its contributors 15945fe691Sjdolecek.\" may be used to endorse or promote products derived from this software 16945fe691Sjdolecek.\" without specific prior written permission. 17945fe691Sjdolecek.\" 18945fe691Sjdolecek.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19945fe691Sjdolecek.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20945fe691Sjdolecek.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21945fe691Sjdolecek.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22945fe691Sjdolecek.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23945fe691Sjdolecek.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24945fe691Sjdolecek.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25945fe691Sjdolecek.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26945fe691Sjdolecek.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27945fe691Sjdolecek.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28945fe691Sjdolecek.\" SUCH DAMAGE. 29945fe691Sjdolecek.\" 30945fe691Sjdolecek.\" @(#)symlink.7 8.3 (Berkeley) 3/31/94 31945fe691Sjdolecek.\" 32*ba0aa175Smaxv.Dd March 25, 2019 33945fe691Sjdolecek.Dt SYMLINK 7 34945fe691Sjdolecek.Os 35945fe691Sjdolecek.Sh NAME 36945fe691Sjdolecek.Nm symlink 37945fe691Sjdolecek.Nd symbolic link handling 3866bb8e21Swiz.Sh DESCRIPTION 39945fe691SjdolecekSymbolic links are files that act as pointers to other files. 40945fe691SjdolecekTo understand their behavior, you must first understand how hard links 41945fe691Sjdolecekwork. 42945fe691Sjdolecek.Pp 43945fe691SjdolecekA hard link to a file is indistinguishable from the original file because 44945fe691Sjdolecekit is a reference to the object underlying the original file name. 45945fe691SjdolecekChanges to a file are independent of the name used to reference the 46945fe691Sjdolecekfile. 47945fe691SjdolecekHard links may not refer to directories and may not reference files 48945fe691Sjdolecekon different file systems. 49945fe691Sjdolecek.Pp 50945fe691SjdolecekA symbolic link contains the name of the file to which it is linked, 51945fe691Sjdoleceki.e. 52945fe691Sjdolecekit is a pointer to another name, and not to an underlying object. 53945fe691SjdolecekFor this reason, symbolic links may reference directories and may span 54945fe691Sjdolecekfile systems. 55945fe691Sjdolecek.Pp 56945fe691SjdolecekBecause a symbolic link and its referenced object coexist in the filesystem 57945fe691Sjdolecekname space, confusion can arise in distinguishing between the link itself 58945fe691Sjdolecekand the referenced object. 59945fe691SjdolecekHistorically, commands and system calls have adopted their own link 60945fe691Sjdolecekfollowing conventions in a somewhat ad-hoc fashion. 61945fe691SjdolecekRules for more a uniform approach, as they are implemented in this system, 62945fe691Sjdolecekare outlined here. 63945fe691SjdolecekIt is important that local applications conform to these rules, too, 64945fe691Sjdolecekso that the user interface can be as consistent as possible. 65945fe691Sjdolecek.Pp 66945fe691SjdolecekSymbolic links are handled either by operating on the link itself, 67945fe691Sjdolecekor by operating on the object referenced by the link. 68945fe691SjdolecekIn the latter case, 69945fe691Sjdolecekan application or system call is said to 70945fe691Sjdolecek.Qq follow 71945fe691Sjdolecekthe link. 72945fe691Sjdolecek.Pp 73945fe691SjdolecekSymbolic links may reference other symbolic links, 74945fe691Sjdolecekin which case the links are dereferenced until an object that is 75945fe691Sjdoleceknot a symbolic link is found, 76945fe691Sjdoleceka symbolic link which references a file which doesn't exist is found, 77945fe691Sjdolecekor a loop is detected. 78945fe691SjdolecekLoop detection is done by placing an upper limit on the number of 79945fe691Sjdoleceklinks that may be followed, and an error results if this limit is 80945fe691Sjdolecekexceeded. 81945fe691Sjdolecek.Pp 82945fe691SjdolecekThere are three separate areas that need to be discussed. 83945fe691SjdolecekThey are as follows: 84bee3db8eSjoerg.Pp 85945fe691Sjdolecek.Bl -enum -compact -offset indent 86945fe691Sjdolecek.It 87945fe691SjdolecekSymbolic links used as file name arguments for system calls. 88945fe691Sjdolecek.It 89945fe691SjdolecekSymbolic links specified as command line arguments to utilities that 90945fe691Sjdolecekare not traversing a file tree. 91945fe691Sjdolecek.It 92945fe691SjdolecekSymbolic links encountered by utilities that are traversing a file tree 93945fe691Sjdolecek(either specified on the command line or encountered as part of the 94945fe691Sjdolecekfile hierarchy walk). 95945fe691Sjdolecek.El 960c2e5eb7Swiz.Ss System calls 97945fe691SjdolecekThe first area is symbolic links used as file name arguments for 98945fe691Sjdoleceksystem calls. 99945fe691Sjdolecek.Pp 100945fe691SjdolecekExcept as noted below, all system calls follow symbolic links. 101945fe691SjdolecekFor example, if there were a symbolic link 102945fe691Sjdolecek.Qq Li slink 103945fe691Sjdolecekwhich pointed to a file named 104945fe691Sjdolecek.Qq Li afile , 105945fe691Sjdolecekthe system call 106945fe691Sjdolecek.Qq Li open("slink" ...) 107945fe691Sjdolecekwould return a file descriptor to the file 108945fe691Sjdolecek.Qq afile . 109945fe691Sjdolecek.Pp 110096e8a4dSwizThere are eleven system calls that do not follow links, and which operate 111945fe691Sjdolecekon the symbolic link itself. 112945fe691SjdolecekThey are: 113dd7d5397Sbjh21.Xr lchflags 2 , 114945fe691Sjdolecek.Xr lchmod 2 , 115945fe691Sjdolecek.Xr lchown 2 , 116cbbfa376Schristos.\".Xr lpathconf 2 , 117945fe691Sjdolecek.Xr lstat 2 , 118945fe691Sjdolecek.Xr lutimes 2 , 119945fe691Sjdolecek.Xr readlink 2 , 120cbbfa376Schristos.Xr readlinkat 2 , 121945fe691Sjdolecek.Xr rename 2 , 122cbbfa376Schristos.Xr renameat 2 , 123cbbfa376Schristos.Xr unlinkat 2 . 124945fe691Sjdolecekand 125945fe691Sjdolecek.Xr unlink 2 . 126945fe691SjdolecekBecause 127945fe691Sjdolecek.Xr remove 3 128945fe691Sjdolecekis an alias for 129945fe691Sjdolecek.Xr unlink 2 , 130945fe691Sjdolecekit also does not follow symbolic links. 131cbbfa376SchristosWhen 132cbbfa376Schristos.Xr rmdir 2 133cbbfa376Schristosor 134cbbfa376Schristos.Xr unlinkat 2 135cbbfa376Schristoswith the 136cbbfa376Schristos.Dv AT_REMOVEDIR 137cbbfa376Schristosflag 138cbbfa376Schristosis applied to a symbolic link, it fails with the error 139cbbfa376Schristos.Er ENOTDIR . 140cbbfa376Schristos.Pp 141cbbfa376SchristosThe 142cbbfa376Schristos.Xr linkat 2 143cbbfa376Schristossystem call does not follow symbolic links 144cbbfa376Schristosunless given the 145cbbfa376Schristos.Dv AT_SYMLINK_FOLLOW 146cbbfa376Schristosflag. 147cbbfa376Schristos.Pp 148cbbfa376SchristosThe following system calls follow symbolic links 149cbbfa376Schristosunless given the 150cbbfa376Schristos.Dv AT_SYMLINK_NOFOLLOW 151cbbfa376Schristosflag: 152cbbfa376Schristos.\" .Xr chflagsat 2 , 153cbbfa376Schristos.Xr fchmodat 2 , 154cbbfa376Schristos.Xr fchownat 2 , 155096e8a4dSwiz.Xr fstatat 2 , 156cbbfa376Schristosand 157cbbfa376Schristos.Xr utimensat 2 . 158cbbfa376Schristos.Pp 159cbbfa376SchristosThe owner and group of an existing symbolic link can be changed by 160cbbfa376Schristosmeans of the 161cbbfa376Schristos.Xr lchown 2 162cbbfa376Schristossystem call. 163cbbfa376SchristosThe flags, access permissions, owner/group and modification time of 164cbbfa376Schristosan existing symbolic link can be changed by means of the 165cbbfa376Schristos.Xr lchflags 2 , 166cbbfa376Schristos.Xr lchmod 2 , 167cbbfa376Schristos.Xr lchown 2 , 168cbbfa376Schristosand 169cbbfa376Schristos.Xr lutimes 2 170cbbfa376Schristossystem calls, respectively. 171cbbfa376SchristosOf these, only the flags and ownership are used by the system; 172cbbfa376Schristosthe access permissions are ignored. 173945fe691Sjdolecek.Pp 174945fe691SjdolecekThe 175945fe691Sjdolecek.Bx 4.4 176945fe691Sjdoleceksystem differs from historical 177945fe691Sjdolecek.Bx 4 178945fe691Sjdoleceksystems in that the system call 179945fe691Sjdolecek.Xr chown 2 180945fe691Sjdolecekhas been changed to follow symbolic links. 181cbbfa376SchristosThe 182cbbfa376Schristos.Xr lchown 2 183cbbfa376Schristossystem call was added later when the limitations of the new 184cbbfa376Schristos.Xr chown 2 185cbbfa376Schristosbecame apparent. 186945fe691Sjdolecek.Pp 187945fe691SjdolecekIf the filesystem is mounted with the 188945fe691Sjdolecek.Em symperm 189945fe691Sjdolecek.Xr mount 8 190945fe691Sjdolecekoption, the symbolic link file permission bits have the following effects: 191945fe691Sjdolecek.Pp 192945fe691SjdolecekThe 193945fe691Sjdolecek.Xr readlink 2 194945fe691Sjdoleceksystem call requires read permissions on the symbolic link. 195945fe691Sjdolecek.Pp 196945fe691SjdolecekSystem calls that follow symbolic links will fail without execute/search 197945fe691Sjdolecekpermissions on all the symbolic links followed. 198945fe691Sjdolecek.Pp 199945fe691SjdolecekThe write, sticky, set-user-ID-on-execution and set-group-ID-on-execution 200945fe691Sjdoleceksymbolic link mode bits have no effect on any system calls 201945fe691Sjdolecek.Po 202945fe691Sjdolecekincluding 203945fe691Sjdolecek.Xr execve 2 204945fe691Sjdolecek.Pc . 2050c2e5eb7Swiz.Ss Commands not traversing a file tree 206945fe691SjdolecekThe second area is symbolic links, specified as command line file 207945fe691Sjdolecekname arguments, to commands which are not traversing a file tree. 208945fe691Sjdolecek.Pp 209945fe691SjdolecekExcept as noted below, commands follow symbolic links named as command 210945fe691Sjdolecekline arguments. 211945fe691SjdolecekFor example, if there were a symbolic link 212945fe691Sjdolecek.Qq Li slink 213945fe691Sjdolecekwhich pointed to a file named 214945fe691Sjdolecek.Qq Li afile , 215945fe691Sjdolecekthe command 216945fe691Sjdolecek.Qq Li cat slink 217945fe691Sjdolecekwould display the contents of the file 218945fe691Sjdolecek.Qq Li afile . 219945fe691Sjdolecek.Pp 220945fe691SjdolecekIt is important to realize that this rule includes commands which may 221945fe691Sjdolecekoptionally traverse file trees, e.g. 222945fe691Sjdolecekthe command 223945fe691Sjdolecek.Qq Li "chown file" 224945fe691Sjdolecekis included in this rule, while the command 225945fe691Sjdolecek.Qq Li "chown -R file" 226945fe691Sjdolecekis not 227945fe691Sjdolecek(The latter is described in the third area, below). 228945fe691Sjdolecek.Pp 229945fe691SjdolecekIf it is explicitly intended that the command operate on the symbolic 230945fe691Sjdoleceklink instead of following the symbolic link, e.g., it is desired that 231945fe691Sjdolecek.Qq Li "file slink" 232945fe691Sjdolecekdisplay the type of file that 233945fe691Sjdolecek.Qq Li slink 234945fe691Sjdolecekis, whether it is a symbolic link or not, the 235945fe691Sjdolecek.Fl h 236945fe691Sjdolecekoption should be used. 237945fe691SjdolecekIn the above example, 238945fe691Sjdolecek.Qq Li "file slink" 239945fe691Sjdolecekwould report the type of the file referenced by 240945fe691Sjdolecek.Qq Li slink , 241945fe691Sjdolecekwhile 242945fe691Sjdolecek.Qq Li "file -h slink" 243945fe691Sjdolecekwould report that 244945fe691Sjdolecek.Qq Li slink 245945fe691Sjdolecekwas a symbolic link. 246945fe691Sjdolecek.Pp 247cbbfa376SchristosThere are five exceptions to this rule. 248945fe691SjdolecekThe 249945fe691Sjdolecek.Xr mv 1 250945fe691Sjdolecekand 251945fe691Sjdolecek.Xr rm 1 252945fe691Sjdolecekcommands do not follow symbolic links named as arguments, 253945fe691Sjdolecekbut respectively attempt to rename and delete them. 254945fe691Sjdolecek(Note, if the symbolic link references a file via a relative path, 255945fe691Sjdolecekmoving it to another directory may very well cause it to stop working, 256945fe691Sjdoleceksince the path may no longer be correct). 257945fe691Sjdolecek.Pp 258945fe691SjdolecekThe 259945fe691Sjdolecek.Xr ls 1 260945fe691Sjdolecekcommand is also an exception to this rule. 261945fe691SjdolecekFor compatibility with historic systems (when 262945fe691Sjdolecek.Nm ls 263945fe691Sjdolecekis not doing a tree walk, i.e. 264945fe691Sjdolecekthe 265945fe691Sjdolecek.Fl R 266945fe691Sjdolecekoption is not specified), 267945fe691Sjdolecekthe 268945fe691Sjdolecek.Nm ls 269945fe691Sjdolecekcommand follows symbolic links named as arguments if the 270cbbfa376Schristos.\" .Fl H 271cbbfa376Schristos.\" or 272945fe691Sjdolecek.Fl L 273945fe691Sjdolecekoption is specified, 274945fe691Sjdolecekor if the 275945fe691Sjdolecek.Fl F , 276096e8a4dSwiz.Fl d , 277945fe691Sjdolecekor 278945fe691Sjdolecek.Fl l 279945fe691Sjdolecekoptions are not specified. 280945fe691Sjdolecek(If the 281945fe691Sjdolecek.Fl L 282945fe691Sjdolecekoption is specified, 283945fe691Sjdolecek.Nm ls 284945fe691Sjdolecekalways follows symbolic links. 285945fe691Sjdolecek.Nm ls 286945fe691Sjdolecekis the only command where the 287cbbfa376Schristos.\" .Fl H 288cbbfa376Schristos.\" and 289945fe691Sjdolecek.Fl L 290945fe691Sjdolecekoption affects its behavior even though it is not doing a walk of 291945fe691Sjdoleceka file tree). 292945fe691Sjdolecek.Pp 293945fe691SjdolecekThe 294cbbfa376Schristos.Xr file 1 295cbbfa376Schristosand 296cbbfa376Schristos.Xr stat 1 297cbbfa376Schristoscommands are also exceptions to this rule. 298cbbfa376SchristosThese 299cbbfa376Schristoscommands do not follow symbolic links named as argument by default, 300cbbfa376Schristosbut do follow symbolic links named as argument if the 301cbbfa376Schristos.Fl L 302cbbfa376Schristosoption is specified. 303cbbfa376Schristos.Pp 304cbbfa376SchristosThe 305945fe691Sjdolecek.Bx 4.4 306945fe691Sjdoleceksystem differs from historical 307945fe691Sjdolecek.Bx 4 308945fe691Sjdoleceksystems in that the 309096e8a4dSwiz.Nm chown 310945fe691Sjdolecekand 311cbbfa376Schristos.Nm chgrp 312945fe691Sjdolecekcommands follow symbolic links specified on the command line. 3130c2e5eb7Swiz.Ss Commands traversing a file tree 314945fe691SjdolecekThe following commands either optionally or always traverse file trees: 315945fe691Sjdolecek.Xr chflags 1 , 316945fe691Sjdolecek.Xr chgrp 1 , 317945fe691Sjdolecek.Xr chmod 1 , 318945fe691Sjdolecek.Xr cp 1 , 319945fe691Sjdolecek.Xr du 1 , 320945fe691Sjdolecek.Xr find 1 , 321945fe691Sjdolecek.Xr ls 1 , 322945fe691Sjdolecek.Xr pax 1 , 323945fe691Sjdolecek.Xr rm 1 , 324096e8a4dSwiz.Xr tar 1 , 325945fe691Sjdolecekand 326945fe691Sjdolecek.Xr chown 8 . 327945fe691Sjdolecek.Pp 328945fe691SjdolecekIt is important to realize that the following rules apply equally to 329945fe691Sjdoleceksymbolic links encountered during the file tree traversal and symbolic 330945fe691Sjdoleceklinks listed as command line arguments. 331945fe691Sjdolecek.Pp 332945fe691SjdolecekThe first rule applies to symbolic links that reference files that are 333945fe691Sjdoleceknot of type directory. 334945fe691SjdolecekOperations that apply to symbolic links are performed on the links 335945fe691Sjdolecekthemselves, but otherwise the links are ignored. 336945fe691Sjdolecek.Pp 337945fe691SjdolecekFor example, the command 338945fe691Sjdolecek.Qq Li "chown -R user slink directory" 339945fe691Sjdolecekwill ignore 340945fe691Sjdolecek.Qq Li slink , 341945fe691Sjdolecekbecause the 342945fe691Sjdolecek.Fl h 343945fe691Sjdolecekflag must be used to change owners of symbolic links. 344945fe691SjdolecekAny symbolic links encountered during the tree traversal will also be 345945fe691Sjdolecekignored. 346945fe691SjdolecekThe command 347945fe691Sjdolecek.Qq Li "rm -r slink directory" 348945fe691Sjdolecekwill remove 349945fe691Sjdolecek.Qq Li slink , 350945fe691Sjdolecekas well as any symbolic links encountered in the tree traversal of 351945fe691Sjdolecek.Qq Li directory , 352945fe691Sjdolecekbecause symbolic links may be removed. 353945fe691SjdolecekIn no case will either 354945fe691Sjdolecek.Nm chown 355945fe691Sjdolecekor 356945fe691Sjdolecek.Nm rm 357945fe691Sjdolecekaffect the file which 358945fe691Sjdolecek.Qq Li slink 359945fe691Sjdolecekreferences in any way. 360945fe691Sjdolecek.Pp 361945fe691SjdolecekThe second rule applies to symbolic links that reference files of type 362945fe691Sjdolecekdirectory. 363945fe691SjdolecekSymbolic links which reference files of type directory are never 364945fe691Sjdolecek.Qq followed 365945fe691Sjdolecekby default. 366945fe691SjdolecekThis is often referred to as a 367945fe691Sjdolecek.Qq physical 368945fe691Sjdolecekwalk, as opposed to a 369945fe691Sjdolecek.Qq logical 370945fe691Sjdolecekwalk (where symbolic links referencing directories are followed). 371945fe691Sjdolecek.Pp 372945fe691SjdolecekAs consistently as possible, you can make commands doing a file tree 373945fe691Sjdolecekwalk follow any symbolic links named on the command line, regardless 374945fe691Sjdolecekof the type of file they reference, by specifying the 375945fe691Sjdolecek.Fl H 376945fe691Sjdolecek(for 377945fe691Sjdolecek.Qq half\-logical ) 378945fe691Sjdolecekflag. 379945fe691SjdolecekThis flag is intended to make the command line name space look 380945fe691Sjdoleceklike the logical name space. 381945fe691Sjdolecek(Note, for commands that do not always do file tree traversals, the 382945fe691Sjdolecek.Fl H 383945fe691Sjdolecekflag will be ignored if the 384945fe691Sjdolecek.Fl R 385945fe691Sjdolecekflag is not also specified). 386945fe691Sjdolecek.Pp 387945fe691SjdolecekFor example, the command 388945fe691Sjdolecek.Qq Li "chown -HR user slink" 389945fe691Sjdolecekwill traverse the file hierarchy rooted in the file pointed to by 390945fe691Sjdolecek.Qq Li slink . 391945fe691SjdolecekNote, the 392945fe691Sjdolecek.Fl H 393945fe691Sjdolecekis not the same as the previously discussed 394945fe691Sjdolecek.Fl h 395945fe691Sjdolecekflag. 396945fe691SjdolecekThe 397945fe691Sjdolecek.Fl H 398945fe691Sjdolecekflag causes symbolic links specified on the command line to be 399945fe691Sjdolecekdereferenced both for the purposes of the action to be performed 400945fe691Sjdolecekand the tree walk, and it is as if the user had specified the 401945fe691Sjdolecekname of the file to which the symbolic link pointed. 402945fe691Sjdolecek.Pp 403945fe691SjdolecekAs consistently as possible, you can make commands doing a file tree 404945fe691Sjdolecekwalk follow any symbolic links named on the command line, as well as 405945fe691Sjdolecekany symbolic links encountered during the traversal, regardless of 406945fe691Sjdolecekthe type of file they reference, by specifying the 407945fe691Sjdolecek.Fl L 408945fe691Sjdolecek(for 409945fe691Sjdolecek.Qq logical ) 410945fe691Sjdolecekflag. 411945fe691SjdolecekThis flag is intended to make the entire name space look like 412945fe691Sjdolecekthe logical name space. 413945fe691Sjdolecek(Note, for commands that do not always do file tree traversals, the 414945fe691Sjdolecek.Fl L 415945fe691Sjdolecekflag will be ignored if the 416945fe691Sjdolecek.Fl R 417945fe691Sjdolecekflag is not also specified). 418945fe691Sjdolecek.Pp 419945fe691SjdolecekFor example, the command 420945fe691Sjdolecek.Qq Li "chown -LR user slink" 421945fe691Sjdolecekwill change the owner of the file referenced by 422945fe691Sjdolecek.Qq Li slink . 423945fe691SjdolecekIf 424945fe691Sjdolecek.Qq Li slink 425945fe691Sjdolecekreferences a directory, 426945fe691Sjdolecek.Nm chown 427945fe691Sjdolecekwill traverse the file hierarchy rooted in the directory that it 428945fe691Sjdolecekreferences. 429945fe691SjdolecekIn addition, if any symbolic links are encountered in any file tree that 430945fe691Sjdolecek.Nm chown 431945fe691Sjdolecektraverses, they will be treated in the same fashion as 432945fe691Sjdolecek.Qq Li slink . 433945fe691Sjdolecek.Pp 434945fe691SjdolecekAs consistently as possible, you can specify the default behavior by 435945fe691Sjdolecekspecifying the 436945fe691Sjdolecek.Fl P 437945fe691Sjdolecek(for 438945fe691Sjdolecek.Qq physical ) 439945fe691Sjdolecekflag. 440945fe691SjdolecekThis flag is intended to make the entire name space look like the 441945fe691Sjdolecekphysical name space. 442945fe691Sjdolecek.Pp 443945fe691SjdolecekFor commands that do not by default do file tree traversals, the 444945fe691Sjdolecek.Fl H , 445096e8a4dSwiz.Fl L , 446945fe691Sjdolecekand 447945fe691Sjdolecek.Fl P 448945fe691Sjdolecekflags are ignored if the 449945fe691Sjdolecek.Fl R 450945fe691Sjdolecekflag is not also specified. 451945fe691SjdolecekIn addition, you may specify the 452945fe691Sjdolecek.Fl H , 453096e8a4dSwiz.Fl L , 454945fe691Sjdolecekand 455945fe691Sjdolecek.Fl P 456945fe691Sjdolecekoptions more than once; the last one specified determines the 457945fe691Sjdolecekcommand's behavior. 458945fe691SjdolecekThis is intended to permit you to alias commands to behave one way 459945fe691Sjdolecekor the other, and then override that behavior on the command line. 460945fe691Sjdolecek.Pp 461945fe691SjdolecekThe 462945fe691Sjdolecek.Xr ls 1 463945fe691Sjdolecekand 464945fe691Sjdolecek.Xr rm 1 465945fe691Sjdolecekcommands have exceptions to these rules. 466945fe691SjdolecekThe 467945fe691Sjdolecek.Nm rm 468945fe691Sjdolecekcommand operates on the symbolic link, and not the file it references, 469945fe691Sjdolecekand therefore never follows a symbolic link. 470945fe691SjdolecekThe 471945fe691Sjdolecek.Nm rm 472945fe691Sjdolecekcommand does not support the 473945fe691Sjdolecek.Fl H , 474096e8a4dSwiz.Fl L , 475945fe691Sjdolecekor 476945fe691Sjdolecek.Fl P 477945fe691Sjdolecekoptions. 478945fe691Sjdolecek.Pp 479945fe691SjdolecekTo maintain compatibility with historic systems, 480945fe691Sjdolecekthe 481945fe691Sjdolecek.Nm ls 482cbbfa376Schristoscommand acts a little differently. 483cbbfa376SchristosIf you do not specify the 484cbbfa376Schristos.Fl F , 485096e8a4dSwiz.Fl d , 486cbbfa376Schristosor 487cbbfa376Schristos.Fl l 488cbbfa376Schristosoptions, 489cbbfa376Schristos.Nm ls 490cbbfa376Schristoswill follow symbolic links specified on the command line. 491cbbfa376SchristosIf the 492945fe691Sjdolecek.Fl L 493945fe691Sjdolecekflag is specified. 494945fe691SjdolecekIf the 495945fe691Sjdolecek.Fl L 496945fe691Sjdolecekflag is specified, 497945fe691Sjdolecek.Nm ls 498945fe691Sjdolecekfollows all symbolic links, 499945fe691Sjdolecekregardless of their type, 500945fe691Sjdolecekwhether specified on the command line or encountered in the tree walk. 501945fe691SjdolecekThe 502945fe691Sjdolecek.Nm ls 503945fe691Sjdolecekcommand does not support the 504945fe691Sjdolecek.Fl H 505945fe691Sjdolecekor 506945fe691Sjdolecek.Fl P 507945fe691Sjdolecekoptions. 5080901655fSjruoho.Ss Magic symlinks 5090901655fSjruohoSo-called 5100901655fSjruoho.Dq magic symlinks 5110901655fSjruohocan be enabled by setting the 512d4a648c3Smjf.Dq vfs.generic.magiclinks 5130901655fSjruohovariable with 514d4a648c3Smjf.Xr sysctl 8 . 515d4a648c3SmjfWhen magic symlinks are enabled 51665412a27Sthorpej.Dq magic 517d4a648c3Smjfpatterns in symlinks are expanded. 51865412a27SthorpejThose patterns begin with 51965412a27Sthorpej.Dq @ 52065412a27Sthorpej.Pq an at-sign , 52165412a27Sthorpejand end at the end of the pathname component 52265412a27Sthorpej.Po 52365412a27Sthorpeji.e. at the next 52465412a27Sthorpej.Dq / , 52565412a27Sthorpejor at the end of the symbolic link if there are no more slashes 52665412a27Sthorpej.Pc . 52765412a27Sthorpej.Pp 52865412a27SthorpejTo illustrate the pattern matching rules, assume that 52965412a27Sthorpej.Dq @foo 53065412a27Sthorpejis a valid magic string: 53165412a27Sthorpej.Pp 53265412a27Sthorpej.Bl -tag -width @foo/barxxxxx -offset indent -compact 53365412a27Sthorpej.It @foo 53465412a27Sthorpejwould be matched 53565412a27Sthorpej.It @foo/bar 53665412a27Sthorpejwould be matched 53765412a27Sthorpej.It bar@foo 53865412a27Sthorpejwould be matched 53965412a27Sthorpej.It @foobar 54065412a27Sthorpejwould not be matched 54165412a27Sthorpej.El 54265412a27Sthorpej.Pp 543d379332aSthorpejMagic strings may also be delimited with 544d379332aSthorpej.Sq { 545d379332aSthorpejand 546d379332aSthorpej.Sq } 547d379332aSthorpejcharacters, allowing for more complex patterns in symbolic links such as: 548d379332aSthorpej.Bd -literal -offset indent 549d379332aSthorpej@{var1}-@{var2}.@{var3} 550d379332aSthorpej.Ed 551d379332aSthorpej.Pp 55265412a27SthorpejThe following patterns are supported: 5530901655fSjruoho.Bl -tag -width @machine_arch -offset indent 55465412a27Sthorpej.It @domainname 55565412a27SthorpejExpands to the machine's domain name, as set by 55665412a27Sthorpej.Xr setdomainname 3 . 55765412a27Sthorpej.It @hostname 55865412a27SthorpejExpands to the machine's host name, as set by 55965412a27Sthorpej.Xr sethostname 3 . 560d379332aSthorpej.It @emul 561d379332aSthorpejExpands to the name of the current process's emulation. 5629f6dc01cSchristosDefaults to 5639f6dc01cSchristos.Dv netbsd . 5649f6dc01cSchristosOther valid emulations are: 5659f6dc01cSchristos.Dv aout , 5669f6dc01cSchristos.Dv aoutm68k , 5679f6dc01cSchristos.Dv freebsd , 5689f6dc01cSchristos.Dv linux , 5699f6dc01cSchristos.Dv linux32 , 5709f6dc01cSchristos.Dv m68k4k , 5719f6dc01cSchristos.Dv netbsd32 , 5729f6dc01cSchristos.Dv sunos , 5739f6dc01cSchristos.Dv sunos32 , 5749f6dc01cSchristos.Dv ultrix , 5759f6dc01cSchristos.Dv vax1k . 57665412a27Sthorpej.It @kernel_ident 57765412a27SthorpejExpands to the name of the 57865412a27Sthorpej.Xr config 1 57965412a27Sthorpejfile used to generate the running kernel. 5809f6dc01cSchristosFor example 5819f6dc01cSchristos.Dv GENERIC . 58265412a27Sthorpej.It @machine 58365412a27SthorpejExpands to the value of 58465412a27Sthorpej.Li MACHINE 585b510fd74Sdhollandfor the system. 586b510fd74SdhollandFor native binaries, this is 58765412a27Sthorpejequivalent to the output of 58865412a27Sthorpej.Dq uname -m 5898883daf1Schristosor 5909f6dc01cSchristos.Xr sysctl 3 591b510fd74Sdholland.Dq hw.machine . 592b510fd74Sdholland.Po 593b510fd74SdhollandFor non-native binaries, the values returned by uname and sysctl 594b510fd74Sdhollandtypically vary to match the emulation environment. 595b510fd74Sdholland.Pc 59665412a27Sthorpej.It @machine_arch 59765412a27SthorpejExpands to the value of 59865412a27Sthorpej.Li MACHINE_ARCH 599b510fd74Sdhollandfor the system. 600b510fd74SdhollandFor native binaries, this is 60165412a27Sthorpejequivalent to the output of 60265412a27Sthorpej.Dq uname -p 6038883daf1Schristosor 6049f6dc01cSchristos.Xr sysctl 3 605b510fd74Sdholland.Dq hw.machine_arch . 606b510fd74Sdholland.Po 607b510fd74SdhollandFor non-native binaries, the values returned by uname and sysctl 608b510fd74Sdhollandtypically vary to match the emulation environment. 609b510fd74Sdholland.Pc 61065412a27Sthorpej.It @osrelease 61165412a27SthorpejExpands to the operating system release of the running kernel 61265412a27Sthorpej.Po 61365412a27Sthorpejequivalent to the output of 61465412a27Sthorpej.Dq uname -r 6158883daf1Schristosor 6169f6dc01cSchristos.Xr sysctl 3 6178883daf1Schristos.Dq kern.osrelease 6188883daf1Schristos.Pc . 61965412a27Sthorpej.It @ostype 62065412a27SthorpejExpands to the operating system type of the running kernel 62165412a27Sthorpej.Po 62265412a27Sthorpejequivalent to the output of 62365412a27Sthorpej.Dq uname -s 6248883daf1Schristosor 6259f6dc01cSchristos.Xr sysctl 3 6268883daf1Schristos.Dq kern.ostype 6278883daf1Schristos.Pc . 62865412a27SthorpejThis will always be 62965412a27Sthorpej.Dq NetBSD 63065412a27Sthorpejon 63165412a27Sthorpej.Nx 63265412a27Sthorpejsystems. 633d4a648c3Smjf.It @ruid 634091bd2e2SreedExpands to the real user-id of the process. 6359477ac30Selad.It @uid 6369477ac30SeladExpands to the effective user-id of the process. 637d2cb1665Schristos.It @rgid 638d2cb1665SchristosExpands to the real group-id of the process. 639d2cb1665Schristos.It @gid 640d2cb1665SchristosExpands to the effective group-id of the process. 64165412a27Sthorpej.El 642945fe691Sjdolecek.Sh SEE ALSO 643945fe691Sjdolecek.Xr chflags 1 , 644945fe691Sjdolecek.Xr chgrp 1 , 645945fe691Sjdolecek.Xr chmod 1 , 646945fe691Sjdolecek.Xr cp 1 , 647945fe691Sjdolecek.Xr du 1 , 648945fe691Sjdolecek.Xr find 1 , 649945fe691Sjdolecek.Xr ln 1 , 650945fe691Sjdolecek.Xr ls 1 , 651945fe691Sjdolecek.Xr mv 1 , 652945fe691Sjdolecek.Xr pax 1 , 653945fe691Sjdolecek.Xr rm 1 , 654945fe691Sjdolecek.Xr tar 1 , 655f6a26780Swiz.Xr uname 1 , 656945fe691Sjdolecek.Xr chown 2 , 657945fe691Sjdolecek.Xr execve 2 , 658dd7d5397Sbjh21.Xr lchflags 2 , 659945fe691Sjdolecek.Xr lchmod 2 , 660945fe691Sjdolecek.Xr lchown 2 , 661945fe691Sjdolecek.Xr lstat 2 , 662945fe691Sjdolecek.Xr lutimes 2 , 663945fe691Sjdolecek.Xr mount 2 , 664945fe691Sjdolecek.Xr readlink 2 , 665945fe691Sjdolecek.Xr rename 2 , 666945fe691Sjdolecek.Xr symlink 2 , 667945fe691Sjdolecek.Xr unlink 2 , 668945fe691Sjdolecek.Xr fts 3 , 669945fe691Sjdolecek.Xr remove 3 , 670945fe691Sjdolecek.Xr chown 8 , 6710c2e5eb7Swiz.Xr mount 8 672a70aaa0aSrillig.Sh HISTORY 673a70aaa0aSrilligMagic symlinks appeared in 674a70aaa0aSrillig.Nx 4.0 . 675