ln - Linux command line command to create link to another fileFollow @ggarron
ln makes links to files.
So you can have only one file that is accessible from two or more parts of your directory structure.
There are two different kinds of links hard or symbolic, to directories you can only create symbolic but not hard links.
ln [OPTION]... [-T] TARGET LINK_NAME (1st form) ln [OPTION]... TARGET (2nd form) ln [OPTION]... TARGET... DIRECTORY (3rd form) ln [OPTION]... -t DIRECTORY TARGET... (4th form)
In the 1st form, create a link to TARGET with the name LINK_NAME. In the 2nd form, create a link to TARGET in the current directory. In the 3rd and 4th forms, create links to each TARGET in DIRECTORY. Create hard links by default, symbolic links with --symbolic. When creating hard links, each TARGET must exist.
- --backup -b
- If the ln utility will remove a file, with this option it makes a backup, usable only when --force is also used
- --force -f
- This option removes the LINK_NAME if it exists before creating the new one, by default ln does not create the link
- --symbolic -s
- Creates symbolic links, which lets you create links to files and also to directories which may be on different filesystems. by default ln creates hard links
Hard links should be on the same filesystem, and can not be pointed to directories, otherwise symlinks can point to files that are on different filesystems and can also point to directories.
To better understand the difference lets see how Linux manage files Each file is composed by two parts:
The inode contains some info like permissions and other info and also the address where the Data is.
Ok two different file names may point to the same inode, therefore to the same Data, this is know as hardlink.
With the symbolic link, the filename points to a different inode and to a different data, but that data is actually a path to the referenced file, the OS recognize that this is a special file so instead of using the data of this file, it follows to the referenced file and acts on that file.
As you can see symbolic links needs an extra step to reach the pointed file.