vanero.blogg.se

Unix link ln
Unix link ln












Think of a hard link as file content having a presence in multiple locations or through different names. Think of a symbolic link as being a "pointer" to a file. There is no difference between the two (or more) files that refer to the same data content other than their names or locations (or both). When you create a hard link, you simply create a second reference to file content that resides somewhere in a file system. While a symbolic link simply points to another file, a hard link and the file that it was created to connect to are really no different from each other. And, if you look at the content of a hard link, you won't see anything that tells you that the file is any different than most of the files you work with on a daily basis. There's no special character that tells you that a file is a hard link. Unlike symbolic links, hard links are not so easily identified on the command line.

unix link ln

In fact, having both types of files called "links" can be somewhat misleading. Hard links are an altogether different kind of file. This might be intended as another way to prevent loops from forming. In addition, hard links can only be used for files - not for directories. $ ln -s myself myselfĬat: myself: Too many levels of symbolic links Symbolic links do not require that the file being pointed to exists on the system. While it might not be apparent in the example below, the file myself did not exist before the ln command was used. Lrwxrwxrwx 1 lguy lguy 7 Apr 26 08:46 otherlink -> onelinkĬat: onelink: Too many levels of symbolic links Lrwxrwxrwx 1 lguy lguy 9 Apr 26 08:46 onelink -> otherlink

You'd also see this if each of two links pointed at each other or a series of symbolic links eventually looped around to the first in the list. If we create a symbolic link that points to itself, the OS will determine that it would go into an infinite loop trying to resolve it and issues a "too many levels of symbolic links". The command ln -s orig mycopy will create a file named mycopy that points to a file named orig. Note that the order of files in the ln command is important. Lrwxrwxrwx 1 ec2-user ec2-user 30 Apr 25 21:10 AU -> /opt/apps/maps/world/australia Notice that the link in this case is using an absolute pathname where the one shown earlier was relative (in the current directory). This one points to a file in an altogether different directory. Looking at the symlink listed above, note that we have to use a special command - readlink - to see its contents as the OS will assume we want to see the contents of the file that it refers to - not the link itself. And, to be honest, a symbolic link could actually be set up to point to itself, though there would be little value in such a link.

unix link ln

If you were to look at the contents of a symbolic link, you would see very clearly that all it contains is the file system path (absolute or relative) to some other file on the system - usually in another directory, though this won't always be the case.

unix link ln

How soft (symbolic) links work is easy to determine. lrwxrwxrwx 1 lguy lguy 5 maybe-not -> maybe The first character in a long listing gives this away quite easily. If you look at a symbolic link using the ls command, you can easily tell that it's a symbolic link. A soft or "symbolic" link is simply a file that points to another file. It's not an issue of malleability, but a very big difference in how each type of link is implemented in the file system. Hard vs soft linksĭon't let the names fool you. Let's look at how links can be most useful, how you can find and identify them, and what you need to consider when setting them up. Symbolic and hard links provide a way to avoid duplicating data on Unix/Linux systems, but the uses and restrictions vary depending on which kind of link you choose to use.












Unix link ln