commands

ln — create hard or symbolic links

Creates a hard link by default, or a symlink with -s. Hard links share inode identity and normally cannot cross filesystems; symbolic links store path text, resolved relative to their own parent for relative targets. Examples assume a fresh chapter files lab.

Formal Syntax & Structure

linux syntaxlinux
ln [OPTION]... TARGET LINK_NAME

Parameters & Attributes

NameTypeDescription
-soptionCreate symbolic link
TARGEToperandExisting object for hard link; path text for symlink
LINK_NAMEoperandNew name

Return Value

filesystem change and exit status

GNU ln returns 0 when link creation succeeds and nonzero on failure. Verify hard-link inode identity or the stored symlink target; a successful symlink creation does not require the target to exist.

Working Example

Example Snippetlinux
ln -s ../notes/hello.txt archive/shortcut
Linux Reference