Tanti Technology

My photo
Bangalore, karnataka, India
Multi-platform UNIX systems consultant and administrator in mutualized and virtualized environments I have 4.5+ years experience in AIX system Administration field. This site will be helpful for system administrator in their day to day activities.Your comments on posts are welcome.This blog is all about IBM AIX Unix flavour. This blog will be used by System admins who will be using AIX in their work life. It can also be used for those newbies who want to get certifications in AIX Administration. This blog will be updated frequently to help the system admins and other new learners. DISCLAIMER: Please note that blog owner takes no responsibility of any kind for any type of data loss or damage by trying any of the command/method mentioned in this blog. You may use the commands/method/scripts on your own responsibility. If you find something useful, a comment would be appreciated to let other viewers also know that the solution/method work(ed) for you.

Tuesday, 10 December 2013

How to create Hard link & Soft Link in AIX



There are 2 types of links can be created in AIX:

  1. Hard link
  2. 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.

  1. Hard link:
    1. Permissions will be same on source & destinatin file linked through hard link.
    2. File size remain same on both the files.
    3. Inode number is same as well.
    4. 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                <--- o:p="" 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:

  1. Soft link:
    1. Permissions will be different on source and destination files in soft link.
    2. File size will not remain the same.
    3. Inode number  will be different for soft linked files.
    4. 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.

 

No comments:

Post a Comment