Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Use the ln command of linux to create a link to the file

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you the use of linux's ln command to create links for the file, I believe that most people do not know much about it, so share this article for you to learn, I hope you will learn a lot after reading this article, let's go to learn the method!

Ln command is a very important command in linux system. The English full name is "link", which means link. Its function is to establish a synchronous link for a file in another location. One is hard link, also known as hard links; the other is symbolic link, also known as symbolic links.

To understand it colloquially, you can think of a hard link as a copy of the source file, which is the same size as the source file, but actually does not take up any space. Symbolic links can be understood as shortcuts like windows.

Symbolic links:

1. Symbolic links exist as paths, similar to shortcuts in the Windows operating system. two。 Symbolic links can span file systems, but hard links cannot. 3. Symbolic links can link to a file name that does not exist, but hard links cannot. 4. Symbolic links can link directories, but hard links cannot.

Hard links:

1. Hard links exist in the form of copies of files, but do not take up actual space. two。 Hard links do not allow you to create hard links to directories. 3. Hard links can only be created in the same file system.

Syntax format: ln [parameters] [source file or directory] [target file or directory]

Common parameters:

-b create a backup file for each existing target file-d this option allows "root" users to establish hard links to directories-f forces the creation of links, even if the target file already exists-n

Treat the symbolic link to the directory as an ordinary file-I interaction mode. If the target file already exists, prompt the user to confirm to overwrite-s to establish a symbolic link to the source file, instead of hard link-v detail mode, the detailed execution process of the output instruction

Reference example

Create a hard link file_1 for the source file file.txt:

[root@linuxcool ~] # ln / root/dir/file.txt. / file_1

Use the "- s" parameter of the ln command to create a symbolic link to the directory, and use the ls command to view the details of the linked file:

[root@linuxcool ~] # ln-s dir file

[root@linuxcool ~] # ls-l

Total dosage 4

-rw-. 1 root root 1138 March 11 14:48 anaconda-ks.cfg

Drwxr-xr-x. 2 root root 36 April 3 08:47 test

Lrwxrwxrwx. 1 root root 4 April 3 08:54 file-> dir

Use the "- v" parameter of the ln command to output the detailed execution of the command:

[root@linuxcool] # ln-v / root/dir/file.txt. / file_1

'. / file_1' = >' / root/dir/file.txt'

Use the "- b" command of the ln command to create a backup file of the target file, and use the ls command to view:

[root@linuxcool] # ln-b / root/dir/file.txt. / file_1

[root@linuxcool ~] # ls

Anaconda-ks.cfg file_1 file_1~ dir

The above is all the contents of using linux's ln command to create a link to the file, thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report