How Linux File Links Work?

Asked 2 years ago, Updated 2 years ago, 40 views

CentOS 8, running on VM Virtual Box. First, we created data1, and then we created a symbolic link to it, data1.sl. After deleting data1, I ran cat data1.sl and it said, "There are no such files or directories." By the way, if you enter the command ln -s data1.cp data1.sl, it says the file is present. Of course, it's a problem that can be solved well I suddenly wonder why it works like this.

I'm waiting for the help of the master Linux staff

linux

2022-09-20 17:40

1 Answers

It's not on Cilantro Linux, but... It's a simple story, so I'll pretend to know.

First, we created data1, and then we created a symbolic link to it, data1.sl.

At this point, both the data1.cp file and the data1.sl file exist. And don't forget that data1.sl is a special file that points to data1.cp.

After deleting data1, I ran cat data1.sl and it said, "There are no such files or directories."

It's a matter of course. When running cat data1.sl, the OS finds that the file data1.sl points to is data1.cp and attempts to run cat data1.cp. Also, data1.cp has been deleted, so an error occurs that such a file does not exist.

By the way, if you enter the command ln -s data1.cp data1.sl, the file appears.

It's a matter of course. When you run ln -s AB , by default, you create a B file, which is a symbolic link file and the link points to A. So the OS will try to create data1.sl. However, data1.sl already exists. (Only data1.cp has been deleted.) Therefore, an error is returned stating that the file is present (cannot be created again).

It's not hard, is it?
Read more: "Symbolic Link" Wikipedia


2022-09-20 17:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.