![]() ![]() Questions and suggestions are always welcome.AIX Version 4.3 Commands Reference, Volume 3 I do hope you learned to use the ln command effectively in this tutorial. I highly recommend reading the following articles that relate to links concept in Linux: Just look in the /lib directory and you'll see plenty of soft links. You'll find them used at many places in your systems. This way, the program can be run from anywhere on the system and the executable of the program remains in its original program folder. This is where you can create a link to this executable file in the /usr/bin directory. If you move the executable to this directory, it may not work as it needs to access some of the code and it won't find the path to these files from the /usr/bin directory. But to run the program from anywhere, you need to put its executable in the /usr/bin directory. You keep the entire thing in the /opt directory. Let's say you downloaded a software that comes with its code and an executable file. Now that you know how to create links, let's briefly why do we need links? What practical purpose do they serve? This image explains the example better: Why do we need links? The -f options stands for 'follow' as in 'follow the chain'. To find the original file from a chain of links, you can use the readlink -f in the following fashion: readlink -f soft_link In the long listing, the second link will point to first link. For example, you create a link to a file and then create another link to the first link. Normally, when you use the ls command with the -loption, it shows the file it points to.īut if there is chain of links, it won't show the original file. Bonus Tip: Getting the original file following a chain of links Mind to add the s for soft link otherwise you'll convert the soft link to hard link. Here's what you can do: ln -sf new_file existing_soft_link Suppose, you want to force update a symbolic link. -f: The force mode just updates the existing link without any confirmation.-i: The interactive mode asks you if you want to overwrite the existing link.The ln command has two options for this purpose: By default, if you try to use an existing link to point to a new file, it will throw you an error: ln: failed to create symbolic link 'soft-link-to-file': File exists Update an existing soft link (or hard link) Hard link to a directory is not possible (normally). You’ll notice that the color of the soft link and hard link is usually different in the Linux terminal. You just need to replace the target file name/path with the directory name/path. Create soft link to a directoryĬreating a soft link to a directory is the same as creating symbolic link to a file. You'll also notice that links start with l instead of the usual - for files in the long listing view.Įven if your terminal doesn't show soft links in different color, you can identify links in this way. Most Linux terminals will show the soft link in a different color along with the destination it points to. To create a symbolic link to a file, use the option -s with the target file name and the link name ln -s target_file link_name To create a hard link to a file, you can use the ln command without any options like this: ln target_file link_name 2. Let me show you some examples of using the ln command to create links in Linux. The syntax for ln command is simple: ln target_file link_name In this tutorial, I'll show you how to use the ln command for creating various types of links in Linux. This picture shows how the two types of links work:īoth hard links and soft links are created with the ln command. Hard link: This points to the memory location of the original file. ![]() Soft link or symbolic link: This is merely a shortcut to the original file.Links give the same file multiple names and allowing them to live in two or more locations simultaneously. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |