How to create Hard link & Soft Link in AIX
There are 2 types
of links can be created in AIX:
- Hard link
- Soft link
When 2 files are
linked amongst themselves, it may be a hard link or it may be a soft linking
depending upon the command used in each case by the admin as per end user
requirement.
- Hard link:
- Permissions will be same on source
& destinatin file linked through hard link.
- File size remain same on both the
files.
- Inode number is same as well.
- If source or destination file gets
corrupted, either 1 of them can be recovered using the other file.
Note: while creating a
link, source file should always be an existing one.
Let’s say there’s
a source file named file1.txt (created using # touch file1.txt command)
and admin wants to link it to another file file2.txt
Commands
for hard link:
# ln file1 file2
<--- Syntax
# touch file1.txt
# ln file1.txt file2.txt
Once the linking
is done, if file2 does not exist, it will be created and will be linked to
file1. This can be verified by using the following command:
#ls -li
24 -rw-r--r-- 2
root system 10 Apr 02 14:07 file1.txt
24 -rw-r--r-- 2
root system 10 Apr 02 14:07 file2.txt
#
Now admin can add
contents to file1 by:
# cat > file1.txt
Verify the
contents entered in file1 from file2 which is linked to file1 by running the
following command:
# cat < file2.txt
Now remove file
file1 and still the contents of file1 can be recovered from file2:
# rm file1.txt
# cat < file2.txt
Command
for Soft link:
- Soft link:
- Permissions will be different on
source and destination files in soft link.
- File size will not remain the same.
- Inode number will be different for soft linked files.
- If destination file is corrupted,
can be recovered from the source file. But if the source file gets
corrupted, it cannot be recovered from the destination file.
# ln –s file1.txt file2.txt
# ls –li
24 -rw-r--r-- 1 root
system 19 Apr 02 14:18 file1.txt
313 lrwxrwxrwx 1 root
system 9 Apr 02 14:18 file2.txt
-> file1.txt
#
# cat > file1.txt
# cat < file2.txt
For Removal,
# rm file1.txt
# cat < file2.txt
There will be no
output for the above command.