Follow the steps below to gain a better understanding of the linking capabilitie
ID: 3880062 • Letter: F
Question
Follow the steps below to gain a better understanding of the linking capabilities in Linux. You should be logged into your Linux system as a normal user. Complete all steps and answer all questions. Submit this document to the instructor by the due date stated in Moodle.
Creating a set of test files
Create a test directory called “LinkLab” in your home dir. Note the casing.
Navigate into the new “LinkLab” dir and enter the following commands:
echo This is test file number 1 > testfile1
echo This is test file number 2 > testfile2
echo This is test file number 3 > testfile3
Verify that you have the three files created and that they contain the lines above.
For example, use the cat command against testfile2 to make sure the output is: “This is test file number 2”
Examining the inode number for files
Make sure you are in the LinkLab dir and run the following command:
ls –li
Question: What is the difference between the above command and a normal ls –l command?
Info: If you examine the output of ls –il you’ll see a numeric value on the far left of the output. This is known as an “inode” number. Each file and directory is referenced through the OS via a number, not a name. This allows you to rename the file without rearranging the bit pattern on the disk itself. It also allows the OS to find the bits on the disk when you provide the friendly filename.
Make a note of the 3 inode numbers that are attached to the 3 files you created.
Link creation
Enter the following command and then examine the directory using ls –l.
ln –s testfile1 linkfile1
Question: What was created?
Question: Can you tell that the new object is a link? How? (there are two ways to id links of this type)
Question: What type of link is this?
Enter the following command and then examine the directory using ls –l.
ln testfile2 linkfile2
Question: What was created?
Question: Can you tell that the new object is a link?
Examine the directory so you can view the inode numbers (see previous section). Look carefully at the inode numbers for the files: testfile2 and linkfile2.
Question: Do the inode numbers for the two files (testfile2 linkfile2) differ?
Question: What type of link is this?
Question: What advantages/disadvantages are there for this type of link?
Create both links type for testfile3.
Using relative paths or absolute paths create a symbolic link to testfile1 in your home dir called shortcut1.
Using relative paths or absolute paths create a hard link to testfile2 in your home dir called shortcut2.
Examine your home directory.
Question: Can you tell which “shortcut” file is a symbolic link? How?
Question: Can you tell which “shortcut” file is a hard link? How?
Explanation / Answer
#Creating a set of test files
cd ~
mkdir LinkLab
cd ~/LinkLab
echo This is test file number 1 > testfile1
echo This is test file number 2 > testfile2
echo This is test file number 3 > testfile3
#verification of files
cat testfile1 testfile2 testfile3
#output
This is test file number 1
This is test file number 2
This is test file number 3
#Examining the inode number for files
cd ~/LinkLab
ls -li
Question: What is the difference between the above command and a normal ls –l command?
Answer: The unique identifier(inode number) for the file is listed using the -i option in ls command
8296573 -rw-r--r-- 1 user1 user1 27 2018-01-28 22:57 testfile1
8296575 -rw-r--r-- 1 user1 user1 27 2018-01-28 22:57 testfile2
8296588 -rw-r--r-- 1 user1 user1 27 2018-01-28 22:57 testfile3
# Link creation
# Enter the following command and then examine the directory using ls –l.
ln -s testfile1 linkfile1
ls -li testfile1 linkfile1
12730134 lrwxrwxrwx 1 user1 user1 9 2018-01-28 23:19 linkfile1 -> testfile1
8296573 -rw-r--r-- 1 user1 user1 27 2018-01-28 22:57 testfile1
Question: What was created?
Answer: A symbolic link (linkfile1) was created for the actual file testfile1
(symbolic links refer to a symbolic path indicating the abstract location of another file)
Question: Can you tell that the new object is a link? How? (there are two ways to id links of this type)
Answer:
ls -li testfile1 linkfile1
12730134 lrwxrwxrwx 1 user1 user1 9 2018-01-28 23:19 linkfile1 -> testfile1
8296573 -rw-r--r-- 1 user1 user1 27 2018-01-28 22:57 testfile1
# Question: What type of link is this?
# Enter the following command and then examine the directory using ls –l.
ln testfile2 linkfile2
Answer: A hardlink file (linkfile2) is created for the actual file testfile2
(hard links refer to the specific location of physical data.)
Question: What was created?
Answer: A hardlink file (linkfile2) is created for the actual file testfile2
Question: Can you tell that the new object is a link?
ls -li testfile2 linkfile2
8296575 -rw-r--r-- 2 user1 user1 27 2018-01-28 22:57 linkfile2
8296575 -rw-r--r-- 2 user1 user1 27 2018-01-28 22:57 testfile2
#Examine the directory so you can view the inode numbers (see previous section). Look carefully at the inode numbers for the files: testfile2 and linkfile2.
Question: Do the inode numbers for the two files (testfile2 linkfile2) differ?
Answer: the inodes for the two files are the same
Question: What type of link is this?
Answer: The type of link is hard link
Question: What advantages/disadvantages are there for this type of link?
symbolic link
Advantages:
symbolic linking when used effectively can be a good substitute to copying and maintaining multiple copies of the files in different folders.
disadvnatages
Deletion or moving the files causes the symlinks to break.
Hard link
Advantages:
Deleting the original file does not cause the link to break or the content to disappear.
No separate inode is required as it is shared between the link and the file.
disadvnatages
Cannot link across file systems. This is because each file system has its own inode table,
so sharing inodes using numbers will not work as these ids might not be the same across inode tables.
Create both links type for testfile3.
ln -s testfile3 sym_linkfile3
ln testfile3 hard_linkfile3
ls -li testfile3 sym_linkfile3 hard_linkfile3
8296588 -rw-r--r-- 2 user1 user1 27 2018-01-28 22:57 hard_linkfile3
3807575 lrwxrwxrwx 1 user1 user1 9 2018-01-28 23:21 sym_linkfile3 -> testfile3
8296588 -rw-r--r-- 2 user1 user1 27 2018-01-28 22:57 testfile3
Using relative paths or absolute paths create a symbolic link to testfile1 in your home dir called shortcut1.
Using relative paths or absolute paths create a hard link to testfile2 in your home dir called shortcut2.
ln -s testfile1 ~/shortcut1
ln testfile1 ~/shortcut2
Examine your home directory.
ls -li ~/shortcut1 ~/shortcut2 ~/LinkLab/testfile1
8296573 -rw-r--r-- 2 user1 user1 27 2018-01-28 22:57 /home/user1/LinkLab/testfile1
12069058 lrwxrwxrwx 1 user1 user1 9 2018-01-28 23:23 /home/user1/shortcut1 -> testfile1
8296573 -rw-r--r-- 2 user1 user1 27 2018-01-28 22:57 /home/user1/shortcut2
# shortcut2 is hardlink to testfile1 we can see the same inode number
# shortcut1 is symbolic link to testfile1 we can see the link as shortcut1 -> testfile1