{
    "mode": "info",
    "parameter": "ln",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/ln/json",
    "generated": "2026-08-05T22:13:25Z",
    "sections": {
        "File: coreutils.info,  Node: ln invocation,  Next: mkdir invocation,  Prev: link invocation,  Up: Special file types": {
            "content": "",
            "subsections": [
                {
                    "name": "12.2 'ln': Make links between files",
                    "content": "'ln' makes links between files.  By default, it makes hard links; with\nthe '-s' option, it makes symbolic (or \"soft\") links.  Synopses:\n\nln [OPTION]... [-T] TARGET LINKNAME\nln [OPTION]... TARGET\nln [OPTION]... TARGET... DIRECTORY\nln [OPTION]... -t DIRECTORY TARGET...\n\n* If two file names are given, 'ln' creates a link to the first file\nfrom the second.\n\n* If one TARGET is given, 'ln' creates a link to that file in the\ncurrent directory.\n\n* If the '--target-directory' ('-t') option is given, or failing that\nif the last file is a directory and the '--no-target-directory'\n('-T') option is not given, 'ln' creates a link to each TARGET file\nin the specified directory, using the TARGETs' names.\n\nNormally 'ln' does not replace existing files.  Use the '--force'\n('-f') option to replace them unconditionally, the '--interactive'\n('-i') option to replace them conditionally, and the '--backup' ('-b')\noption to rename them.  Unless the '--backup' ('-b') option is used\nthere is no brief moment when the destination does not exist; this is an\nextension to POSIX.\n\nA \"hard link\" is another name for an existing file; the link and the\noriginal are indistinguishable.  Technically speaking, they share the\nsame inode, and the inode contains all the information about a file -\nindeed, it is not incorrect to say that the inode is the file.  Most\nsystems prohibit making a hard link to a directory; on those where it is\nallowed, only the super-user can do so (and with caution, since creating\na cycle will cause problems to many other utilities).  Hard links cannot\ncross file system boundaries.  (These restrictions are not mandated by\nPOSIX, however.)\n\n\"Symbolic links\" (\"symlinks\" for short), on the other hand, are a\nspecial file type (which not all kernels support: System V release 3\n(and older) systems lack symlinks) in which the link file actually\nrefers to a different file, by name.  When most operations (opening,\nreading, writing, and so on) are passed the symbolic link file, the\nkernel automatically \"dereferences\" the link and operates on the target\nof the link.  But some operations (e.g., removing) work on the link file\nitself, rather than on its target.  The owner and group of a symlink are\nnot significant to file access performed through the link, but do have\nimplications on deleting a symbolic link from a directory with the\nrestricted deletion bit set.  On the GNU system, the mode of a symlink\nhas no significance and cannot be changed, but on some BSD systems, the\nmode can be changed and will affect whether the symlink will be\ntraversed in file name resolution.  *Note (libc)Symbolic Links::.\n\nSymbolic links can contain arbitrary strings; a \"dangling symlink\"\noccurs when the string in the symlink does not resolve to a file.  There\nare no restrictions against creating dangling symbolic links.  There are\ntrade-offs to using absolute or relative symlinks.  An absolute symlink\nalways points to the same file, even if the directory containing the\nlink is moved.  However, if the symlink is visible from more than one\nmachine (such as on a networked file system), the file pointed to might\nnot always be the same.  A relative symbolic link is resolved in\nrelation to the directory that contains the link, and is often useful in\nreferring to files on the same device without regards to what name that\ndevice is mounted on when accessed via networked machines.\n\nWhen creating a relative symlink in a different location than the\ncurrent directory, the resolution of the symlink will be different than\nthe resolution of the same string from the current directory."
                }
            ]
        },
        "Therefore, many users prefer to first change directories to the location": {
            "content": "where the relative symlink will be created, so that tab-completion or\nother file resolution will find the same target as what will be placed\nin the symlink.\n\nThe program accepts the following options.  Also see *note Common\noptions::.\n\n'-b'\n'--backup[=METHOD]'\n*Note Backup options::.  Make a backup of each file that would\notherwise be overwritten or removed.\n\n'-d'\n'-F'\n'--directory'\nAllow users with appropriate privileges to attempt to make hard\nlinks to directories.  However, note that this will probably fail\ndue to system restrictions, even for the super-user.\n\n'-f'\n'--force'\nRemove existing destination files.\n\n'-i'\n'--interactive'\nPrompt whether to remove existing destination files, and fail if\nthe response is not affirmative.\n\n'-L'\n'--logical'\nIf '-s' is not in effect, and the source file is a symbolic link,\ncreate the hard link to the file referred to by the symbolic link,\nrather than the symbolic link itself.\n\n'-n'\n'--no-dereference'\nDo not treat the last operand specially when it is a symbolic link\nto a directory.  Instead, treat it as if it were a normal file.\n\nWhen the destination is an actual directory (not a symlink to one),\nthere is no ambiguity.  The link is created in that directory.  But\nwhen the specified destination is a symlink to a directory, there\nare two ways to treat the user's request.  'ln' can treat the\ndestination just as it would a normal directory and create the link\nin it.  On the other hand, the destination can be viewed as a\nnon-directory - as the symlink itself.  In that case, 'ln' must\ndelete or backup that symlink before creating the new link.  The\ndefault is to treat a destination that is a symlink to a directory\njust like a directory.\n\nThis option is weaker than the '--no-target-directory' ('-T')\noption, so it has no effect if both options are given.\n\n'-P'\n'--physical'\nIf '-s' is not in effect, and the source file is a symbolic link,\ncreate the hard link to the symbolic link itself.  On platforms\nwhere this is not supported by the kernel, this option creates a\nsymbolic link with identical contents; since symbolic link contents\ncannot be edited, any file name resolution performed through either\nlink will be the same as if a hard link had been created.\n\n'-r'\n'--relative'\nMake symbolic links relative to the link location.  This option is\nonly valid with the '--symbolic' option.\n\nExample:\n\nln -srv /a/file /tmp\n'/tmp/file' -> '../a/file'\n\nRelative symbolic links are generated based on their canonicalized\ncontaining directory, and canonicalized targets.  I.e., all\nsymbolic links in these file names will be resolved.  *Note\nrealpath invocation::, which gives greater control over relative\nfile name generation, as demonstrated in the following example:\n\nln--relative() {\ntest \"$1\" = --no-symlinks && { nosym=$1; shift; }\ntarget=\"$1\";\ntest -d \"$2\" && link=\"$2/.\" || link=\"$2\"\nrtarget=\"$(realpath $nosym -m \"$target\" \\\n--relative-to \"$(dirname \"$link\")\")\"\nln -s -v \"$rtarget\" \"$link\"\n}\n\n'-s'\n'--symbolic'\nMake symbolic links instead of hard links.  This option merely\nproduces an error message on systems that do not support symbolic\nlinks.\n\n'-S SUFFIX'\n'--suffix=SUFFIX'\nAppend SUFFIX to each backup file made with '-b'.  *Note Backup\noptions::.\n\n'-t DIRECTORY'\n'--target-directory=DIRECTORY'\nSpecify the destination DIRECTORY.  *Note Target directory::.\n\n'-T'\n'--no-target-directory'\nDo not treat the last operand specially when it is a directory or a\nsymbolic link to a directory.  *Note Target directory::.\n\n'-v'\n'--verbose'\nPrint the name of each file after linking it successfully.\n\nIf '-L' and '-P' are both given, the last one takes precedence.  If\n'-s' is also given, '-L' and '-P' are silently ignored.  If neither\noption is given, then this implementation defaults to '-P' if the system\n'link' supports hard links to symbolic links (such as the GNU system),\nand '-L' if 'link' follows symbolic links (such as on BSD).\n\nAn exit status of zero indicates success, and a nonzero value\nindicates failure.\n\nExamples:\n\nBad Example:\n\n# Create link ../a pointing to a in that directory.\n# Not really useful because it points to itself.\nln -s a ..\n\nBetter Example:\n\n# Change to the target before creating symlinks to avoid being confused.\ncd ..\nln -s adir/a .\n\nBad Example:\n\n# Hard coded file names don't move well.\nln -s $(pwd)/a /some/dir/\n\nBetter Example:\n\n# Relative file names survive directory moves and also\n# work across networked file systems.\nln -s afile anotherfile\nln -s ../adir/afile yetanotherfile\n",
            "subsections": []
        }
    },
    "flags": [],
    "examples": [],
    "see_also": []
}