Closed Captioning Closed captioning available on our YouTube channel

How to use the In command: 2-Minute Linux Tips

Network World | Mar 20, 2020

In this Linux tip, learn to use the ln command, which can create either type of link on Linux systems.

Copyright © 2020 IDG Communications, Inc.

Hi, this is Sandra Henry-Stocker, author of the “Unix as a Second Language” blog on NetworkWorld.
In this Linux tip, we’re going to look at the ln command that is used to create links on Linux systems. There are two types of links and this command can set up either one.
The most commonly used type of link is a symbolic link. It’s a file that points at another file or directory, thus making it easier to use that file or directory. If you frequently use the wtmp file that tracks logins, for example, and don’t want to remember where it is, you might create a symbolic link to it like this:
Note that, with just one argument, we create a link with the same name as what it points at:
Use the -ld options to get ls to show what the file points to rather than listing the file or the contents of that directory.
In this example, we can now use the who command to look at logins without having to add the full path to the file, change directory or think about where the wtmp file lives.
The other type of link is called a “hard link” and adds a new reference to an existing file which shares the file’s content and metadata (e.g., owner and permissions). It means a file will be in two places at once in your file system even though it’s still a single file – the file’s content is in one location on the disk and the links share the inode. Note that a hard link can only be set up in the same file system as the original file and would be set up like this:
With this command, we will end up with two references to “mylog” files in the file system – the original and the one you just added with ln. The way to tell that the files are the same is to us the ls -i (show inode) command:
Notice that the inode numbers are the same. Either of these file references could be removed and the file and its content would remain intact and available through the other link.
That’s your Linux tip for the ln command.
If you have questions or would like to suggest a topic, please add a comment below. And don’t forget to subscribe to the IDG Tech(talk) channel on YouTube.
If you liked this video, please hit the like and share buttons. For more Linux tips, be sure to follow us on Facebook, YouTube and
Featured videos from