daddyright.blogg.se

Linux soft link example
Linux soft link example










Now let's look at the contents of file1.txt: cat file1.txt This is a file. Let's append a line to one of them using the > operator: echo "It points to data on the disk." > file1.txt If we change the contents of the data pointed to by either one of these files, the other file's contents are changed as well. Here's an illustration to help you visualize it: Both file names point to the same bytes of data on the disk. The important thing to realize is that we did not make a copy of this data. Now both file1.txt and file2.txt point to the same data on the disk: cat file1.txt This is a file. Our first argument is the name of the file whose data we're linking to the second argument is the name of the new link we're creating. The general form of the link command is: " link file_name linkname". In essence, we'll create another file name for the data that already exists. So, let's use link to create our own link to the file data recently created. What the link command does is allow us to manually create a link to file data that already exists. Here's an illustration of the file name and the data to help you visualize it: The file name and the file's data are two separate entities. If you rename the file, the file's contents are not altered only the information that points to it. When this file was created, the operating system wrote the bytes to a location on the disk and also linked that data to a file name, file1.txt so that we can refer to the file in commands and arguments. We can check that it worked using cat to display the file's contents: cat file1.txt This is a file. Normally this would echo to our terminal, but the > operator redirects the string's text to the file1.txt file. This command echoes the string " This is a file". Let's create a file named file1.txt: echo "This is a file." > file1.txt More than one file name can "link" to the same data. What is a link?īefore we discuss the ln command, let's first discuss the link command, what a link is, and how it relates to files as we know them.Ī link is an entry in your file system which connects a file name to the actual bytes of data on the disk.

linux soft link example

When creating hard links, each TARGET must exist. Ln creates hard links by default, or symbolic links if the -s ( -symbolic) option is specified. If LINKNAME is omitted, a link to TARGET is created in the current directory, using the name of TARGET as the LINKNAME.

linux soft link example

Ln creates a link to file TARGET with the name LINKNAME.












Linux soft link example