Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

ln (Unix)

From Wikipedia, the free encyclopedia
(Redirected fromReadlink)
Shell command for creating a link file
ln
Example usage ofln utility
Original authorAT&T Bell Laboratories
DevelopersVariousopen-source andcommercial developers
Initial releaseNovember 3, 1971; 54 years ago (1971-11-03)
Operating systemUnix,Unix-like,IBM i
PlatformCross-platform
TypeCommand
Licensecoreutils:GPLv3+

ln is ashellcommand for creating a link file to an existingfile ordirectory.[1] By default, the command creates ahard link, but with the-scommand line option, it creates asymbolic link.[2] Most systems disallow a hard link to a directory since such links could disrupt the structure of afile system and interfere with the operation of other utilities.[3] The command can create a symbolic link to non-existent file.[4]

The command appeared in Issue 2 of theX/Open Portability Guidelines.[5] The version inGNU Core Utilities was written by Mike Parker and David MacKenzie.[6]The command is available inWindows viaUnxUtils[7] and has been ported toIBM i.[8]

Links

[edit]

A link allows more than onepath to refer to the same file.

A hard link is a directory entry that refers to a file'sinode (an internalreference). A file can have multiple hard links – each referring to the sameinode.[9] Creating a hard link does not copy the contents of the file, but merely causes another name to be associated with the same content. When a hard link is created for a file, acounter in its inode is incremented, and removing a hard link results in decrementing the counter. A file is not deleted (to allow reusing its storage space) until its reference count reaches zero.[1][10] A hard link can only refer to an object on the samefile system.[11]

A symbolic link refers to another file by its path (a symbolic reference).[4] When encountered during pathname resolution, modify thepathname resolution to be taken to the location which the symbolic link contains. The content of a symbolic link is the target path, which can also be examined via thereadlink command.[12] A symbolic link may specify a path that does not refer to an existing file. Resolving such a symbolic link will fail until a file is created at its specified path. Also, a symbolic link to an existing file will fail to resolve if the file is moved.[9]

Use

[edit]

Per theSingle Unix Specification, theln command is specified in the Shell and Utilities (XCU) document.[13]POSIX includes a similar specification.[5]

If neither target file nor target directory are specified, links are created in the currentworking directory.

Options

[edit]

The specification indicates command line options that must be supported:

  • -f (force)Clobbers an existing file if the output path specifies an existing file
  • -L If a source operand specifies a symbolic link, create a hard link to the link's target file
  • -P If a source operand specifies a symbolic link, create a hard link to the symbolic link file
  • -s Create symbolic links instead of hard links; causes-L and-P to be silently ignored

If more than one of the mutually-exclusive options-L and-P is specified, the last option specified determines the resulting behavior.

If the-s option is not specified and neither a-L nor a-P option is specified, the implementation defines which of the-L and-P options is used by default.

Single file invocation

[edit]

The command creates a new link to the path indicated bysource, stored at the path indicated bytarget. The syntax is as follows:

ln [-fs] [-L|-P] source target

Multiple file invocation

[edit]

The command creates a new link to each file specified by thesource_# operands, stored in an existing directory indicated bytarget_dir.

ln [-fs] [-L|-P] source_1 source_2 ... target_dir

Examples

[edit]

The following creates a hard link to filefoo calledbar.

ln foo bar

The following creates a symbolic link to filefoo calledbar.

ln -s foo bar

See also

[edit]

References

[edit]
  1. ^abKernighan, Brian W.; Pike, Rob (1984).The Unix programming environment. Englewood Cliffs, N.J.: Prentice-Hall. p. 59.ISBN 013937681X.
  2. ^"ln - The Open Group Base Specifications Issue 7".pubs.opengroup.org. The IEEE and The Open Group.Archived from the original on 6 March 2019. Retrieved7 August 2015.
  3. ^"Why are hard links not allowed to directories in UNIX/Linux?".unix.stackexchange.com.Archived from the original on 20 November 2015. Retrieved7 August 2015.
  4. ^ab"GNU Coreutils: ln invocation".gnu.org. Free Software Foundation, Inc.Archived from the original on 16 February 2019. Retrieved7 August 2015.
  5. ^abln – Shell and Utilities Reference,The Single UNIX Specification, Version 5 fromThe Open Group
  6. ^ln(1) – Linux General CommandsManual from ManKier.com
  7. ^"Native Win32 ports of some GNU utilities".unxutils.sourceforge.net.Archived from the original on 2006-02-09. Retrieved2025-08-09.
  8. ^IBM."IBM System i Version 7.2 Programming Qshell"(PDF).IBM.Archived(PDF) from the original on 2020-09-18. Retrieved2020-09-05.
  9. ^abLoosemore, Sandra; Stallman, Richard M.; McGrath, Roland; Oram, Andrew; Drepper, Ulrich.The GNU C Library Reference Manual(PDF). Free Software Foundation, Inc. p. 392. Retrieved7 August 2015.
  10. ^"Speaking UNIX: It is all about the inode".ibm.com. IBM developerWorks.Archived from the original on 24 September 2015. Retrieved7 August 2015.
  11. ^Bovet, Daniel P.; Cesati, Marco (2005).Understanding the Linux Kernel (3rd ed.). Boston, MA: Safari Tech Books Online. p. 14.ISBN 0596005652.
  12. ^"readlink(1) - Linux man page".linux.die.net. Retrieved7 August 2015.
  13. ^"The Single UNIX Specification, Version 4 - Overview".unix.org. unix.org.Archived from the original on 15 January 2018. Retrieved7 August 2015.

External links

[edit]
The WikibookGuide to Unix has a page on the topic of:File System Utilities - ln
File system
Processes
User environment
Text processing
Shell builtins
Searching
Documentation
Software development
Miscellaneous
File system
Text utilities
Shell utilities
Retrieved from "https://en.wikipedia.org/w/index.php?title=Ln_(Unix)&oldid=1336328326#Links"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp