To Create Hard Links in Linux
To create a hard links in Linux, we will use ln utility. For example, the following command creates a hard link named tp
to the file topprocs.sh
.
$ ls -l $ ln topprocs.sh tp $ ls -l
Where,
tp
is just another regular executable file that points to the same underlying inode as topprocs.sh
.To make a hard link directly into a soft link, use the -P
flag like this.
$ ln -P topprocs.sh tp
To Create Symbolic Links in Linux
To create a symbolic link in Linux, we will use same ln utility with -s
switch. For example, the following command creates a symbolic link named topps.sh
to the file topprocs.sh
.
$ ln -s ~/bin/topprocs.sh topps.sh $ ls -l topps.sh
Where,
topps.sh
is a link indicated by l:
meaning it is a link to another filename.If the symbolic link already exists, you may get an error, to force the operation (remove existing symbolic link), use the -f
option.
$ ln -s ~/bin/topprocs.sh topps.sh $ ln -sf ~/bin/topprocs.sh topps.sh
To enable verbose mode, add the -v
flag to prints the name of each linked file in the output.
$ ln -sfv ~/bin/topprocs.sh topps.sh $ $ls -l topps.sh