The ln command is used to create links between files. Before going into the application of the ln command in detail, please refer the below link for a clear understanding of the hard link and soft link in Linux. Hard and Soft Links in Linux
ln [OPTION]... [-T] TARGET LINK_NAME (1st form) ln [OPTION]... TARGET... DIRECTORY (2nd form) ln [OPTION]... -t DIRECTORY TARGET... (3rd form)
Basically, ln command is used to create hard links and soft links for files in Linux. Let’s discuss all the three forms one by one.
1st Form: This form is simple, the source file with destination link name you have to specify:
2nd Form: Here, we have to give source file and directory as a link, simply the source file will be copied to the directory which you specify. See the example below.
3rd Form: Here, we will specify the directory name and a file to be linked to the directory. It is mostly same to 2nd form.
Most Useful Options:
- verbose or -v : This option will help you to know which file is linked to which file. Basically, it prints the name of each linked file.
- Help or -h : It will display help option of ln command, you could even see more detailed information in those help command.
- version or -v : This will display the version detail, author detail of the command.
- Symbolic links are most useful for avoiding complicated paths. Don’t want to have to remember a path that is 73 characters long? No problem, just create a symbolic link to remember where it is.
- Symbolic links make it easy to make some set of files appear to exist in multiple locations without having to make separate copies.
- Hard links are most useful for keeping file content in a single location by avoiding duplication of what might be a very large amount of data.
Practical Example of creation and deletion of links in Linux:
- yes command in Linux with Examples
- cp command in Linux with examples
- df Command in Linux with examples
- tee command in Linux with examples
- for command in Linux with Examples
- which command in Linux with examples
- more command in Linux with Examples
- gcc command in Linux with examples
- dir command in Linux with examples
- bg command in Linux with Examples
- fg command in Linux with examples
- rcp Command in Linux with examples
- ed command in Linux with examples
- fc Command in Linux with Examples
- dc command in Linux with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.