Friday, 6 January 2012

Linux Hard and Soft Links Examples

·        Go into the tmp directory:
·        cd /tmp;

·        Make a directory called original
·        mkdir original; cd original;

·        Copy the /etc/host.conf file or any file to test with here
·        cp /etc/host.conf .;

·        List the contents and take note of the inode (first column)
·        ls -il;   = 143265 -rw-r--r-- 1 Nasir Nasir 92 ……. host.conf

·        Create a symbolic link to host.conf called linkhost.conf
·        ln --symbolic -T host.conf linkhost.conf;

·        Now list out the inodes again
·        ls -il;   =132095 lrwxrwxrwx 1 nasir nasir 9 …….. linkhost.conf→host.conf

·        Notice if the the inode for the link is different?
·        Yes, inode for this link is different from the file host.conf

·        Now create a hard link to the same file called hardhost.conf
·        ln -T host.conf hardhost.conf;

·        Now list the inodes one more time
·        ls -il;   = 143265 -rw-r--r-- 1 Nasir Nasir 92 ……. hardhost.conf

·        Notice if the the inode for the link is different?
·        No, inode is same for file and its hard link.

·        Open up linkhost.conf and edit it and save it
·        vi linkhost.conf; (save :wq)

·        Now look in host.conf and notice if the changes were made
·        Yes, same changes appear in host.conf

·        Lets cut/paste host.conf up one directory and see if it causes any problems
·        mv host.conf ../; it moved seccussfully;

·        Do ls -l and see what is the result?
·        the line for linkhost.conf (softlink) appear black indicating broken link.

·        What is the result of cat linkhost.conf?
·        cat: linkhost.conf: No such file or directory

·        What is the result of cat hardhost.conf?
·        it works and opens host.conf although it is moved to upper directory.


Post a Comment

Free Host | lasik surgery new york