Links and the "ln" command
With a hard link, you are creating another instance of the original file. With a hard link, any changes you make to the linked version will be made to the original file.
ln file1 file2
This creates a mirror of file1 with file2. To prove this we can display the files inode number using the "-i" parameter with the list command:
ls -li 105259 -rw-r--r-- 2 john users 0 Aug 10 11:24 file2 105259 -rw-r--r-- 2 john users 0 Aug 10 11:24 file1
Notice the inode number in column one is identical!
Notice the third column contains the number "2" in the reference number (2 files)
Soft links or as they are commonly known "symlinks" are literally are one file that points to another file. When you create a soft link, you are creating a new file file (short cut) that points to an existing file on your system. When you create a soft link, you need to use the "-s" option. (syntax: syntax: ln -s [target] [link name])
As a test I have created a file called "great.txt" in a directory ~loltst/linktest
loltst@ls001a:~/linktest> pwd /home/loltst/linktest loltst@ls001a:~/linktest> ls -l total 4 -rw-r--r-- 1 loltst users 21 Jul 23 10:06 great.txt loltst@ls001a:~/linktest> cat great.txt This is a test file.
Next I created a symbolic link to the file great.txt with the command "ln -s ~loltst/linktest/great.txt john.txt"
loltst@ls001a:~/linktest> ln -s ~loltst/linktest/great.txt john.txt loltst@ls001a:~/linktest> ls -l total 4 -rw-r--r-- 1 loltst users 21 Jul 23 10:06 great.txt lrwxrwxrwx 1 loltst users 31 Jul 23 10:09 john.txt -> /home/loltst/linktest/great.txt
Now I can also issue the command "cat john.txt"
loltst@ls001a:~/linktest> cat john.txt This is a test file.
To remove link simply issue "rm john.txt"