ln
Create links between files
TLDR
Create a symbolic link to a file or directory
Overwrite an existing symbolic link to point to a different file
Create a hard link to a file
SYNOPSIS
ln [OPTION]... TARGET... DIRECTORY
ln [OPTION]... TARGET
ln [OPTION]... TARGET1 TARGET2
PARAMETERS
-b, --backup[=CONTROL]
make a backup of each existing destination file
-d, -F, --directory
allow users with appropriate privileges to attempt to make hard links to directories
-f, --force
remove existing destination files
-i, --interactive
prompt whether to remove existing destination files
-n, --no-dereference
treat LINK_NAME as a normal file if it is a symbolic link to a directory
-s, --symbolic
make symbolic links instead of hard links
-S, --suffix=SUFFIX
override the usual backup suffix
-v, --verbose
print the name of each linked file
--help
display this help and exit
--version
output version information and exit
DESCRIPTION
The ln command in Linux creates links between files. A link allows a file to be accessed by multiple names, or in multiple directories.
There are two main types of links: hard links and symbolic links (also known as soft links).
Hard links share the same inode (index node) as the original file. This means they point directly to the data on the disk. Deleting the original file doesn't delete the data if a hard link exists, as the data is only truly deleted when all hard links to it are removed and the file is closed by all processes using it. Hard links cannot span across file systems.
Symbolic links, on the other hand, are essentially pointers to the original file's path. They contain the path to the original file. If the original file is deleted or moved, the symbolic link will become broken, pointing to a non-existent file. Symbolic links can span across file systems.
CAVEATS
Creating hard links to directories is generally discouraged and may be restricted by the system. Using the '-d' or '-F' options requires appropriate privileges.
HARD LINK LIMITATIONS
Hard links cannot cross file system boundaries. This is because the inode number is unique only within a specific file system. Also, hard links cannot be created for directories (unless using the -d or -F options, but that requires privilege and generally is not recommended for normal users)
SYMBOLIC LINK RESOLUTION
When a program accesses a symbolic link, the operating system follows the link to the target file. If the target file doesn't exist, the program will encounter an error (e.g., 'No such file or directory').
HISTORY
The ln command is a fundamental utility present in virtually all Unix-like operating systems since their earliest versions. Its primary function, creating links, has been essential for file management and organization since the dawn of Unix. The concept of hard links predates symbolic links and was a core part of the original file system design. Symbolic links were introduced later to overcome the limitations of hard links (e.g., the inability to link across file systems). Over time, the command has been standardized and improved but its basic functionality remains largely unchanged.