- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create links between files in the Linux?
Before creating links, we need to understand what is link and how many types of link in the Linux system.
Links are shortcuts to access a file. It is a connection between file name and actual data in the system. We can say that a link is a pointer to a file.
Types of links
There are two types of links in the Linux system.
- Hard Links
- Soft Links or Symbolic links
Hard Links -
The hard link points to the index node of a file, the data of which is stored on the system and the size of link is equal to actual file size.
Soft Links or Symbolic Links -
The soft links are just shortcuts of actual files in the Linux system. It does not contain the contents of the actual file.
The ln command is used to create links between files in the Linux system. By default, the ln command creates a hard link of the file for creating symbolic links, we use -s or --symbolic option with the ln command.
The general syntax of the ln command is as follows.
$ ln [OPTION]... [-T] TARGET LINK_NAME $ ln [OPTION]... TARGET $ ln [OPTION]... -t TARGET... DIRECTORY $ ln [OPTION]... -t DIRECTORY TARGET...
Brief description of options available in the ln command.
|Sr.No.||Option & Description|
Create a backup of existing destination file with argument
Create a backup of existing destination file without argument
Forcefully remove existing destination files
Display a message while removing destination
Create hard links directly to symbolic links
Make symbolic links relative to link location
Create soft links instead of hard links
Specify the directory in which to create the links
Treat name of link as a normal file
Prompt what is being done
Displays a help message and then exits.
It gives info about the version and then exits.
To create a hard link of the file, we use the command specified by file name and link name as shown in below.
$ ln file.txt link.txt
The created link will be a hard link because by default, using the ln command the hard link will be created and the size of the link is equal to the actual size of the file.
To create symbolic link or soft link of a file, we use -s or --symbolic option with the ln command in the Linux system as shown in below.
$ ln --symbolic file.txt link.txt
The color of the symbolic link is different from the actual file or hard link, and also the contents of the file are only in the actual file the symbolic link is just pointing to the file.
Kickstart Your Career
Get certified by completing the courseGet Started