It's usage is as follows:
ln [-Ffhinsv] source_file [target_file]
1st, lets show our current directory
$ pwd /usr/home/user
Now we'll show that there is no temp directory.
$ ls -l temp total 0
So let’s create one, & then display it.
$ mkdir temp $ ls -l | grep temp drwxr-xr-x 2 user user 512 Aug 2 23:08 temp
Again, let’s show that there is no directory named temp2.
$ ls -l | grep temp2 $
Here we will create a symbolic link from temp to a new directory link2. Keep in mind, we never created a directory actually named temp2!
$ ln -s temp temp2 $ ls -l | grep temp2 lrwxr-xr-x 1 user user 4 Aug 2 23:11 temp2 -> temp
Now that we have our symbolic link created, let’s echo some junk into a text file inside of our temp directory. Once we're done with that, we'll display the contents just to show it was created as intended.
$ echo junk > temp/junk.txt $ cat temp2/junk.txt junk
Here you will see the contents of the temp directory & then the temp2 directory, a link to the temp directory.
$ ls -l temp total 2 -rw-r--r-- 1 user user 5 Aug 2 23:13 junk.txt $ ls -l temp2 lrwxr-xr-x 1 user user 4 Aug 2 23:13 temp2 -> temp
Once we're inside of the temp2 directory, we'll issue an ls showing the junk.txt text file that we created inside of temp.
$ cd temp2 $ ls junk.txt
As you can see, once the symbolic link has been created it can be used in reference to the original temp directory. It is important to keep in mind that is simply a similar reference & not a copy! So if you remove anything inside of it, it WILL be removed from them both!





MultiQuote




|