Link Files in linux

2 types of link files are present in linux:

Soft link and Hard link

Soft linkHard link
Shortcut fileBackup file
size of link file is equal to the no of chars in original filenamesize of both files are same
If original file is deleted, link is broken and data is lostif original file is deleted then also link will contain all data
command: ln -s <source_file> <dest_file>command: ln <source_file> <dest_file>

Soft link is similar to shortcut in windows

To execute command/shellscript from anywhere, create a soft link of the file in /usr/local/bin directory

ex:

touch hello.sh
cat > hello.sh
echo "hello world"
^C

execute this file in same directory:

./hello.sh

output: hello world

cd testdir/

execute hello.sh in another directory:

./hello.sh

output: -bash: ./hello.sh: No such file or directory

create a link of this shell script file to directory /usr/local/bin

ln -s /opt/training/hello.sh /usr/local/bin/hello

Now execute hello from any directory:

hello

output: hello world

0
Subscribe to my newsletter

Read articles from Venkateshwar Kurle directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Venkateshwar Kurle
Venkateshwar Kurle