Linux ln usage

Source: Internet
Author: User

This is a very important command in linux. Please be familiar with it. Its function is to create a synchronization link for a file or directory in another location, similar to a hyperlink in Windows.

The most common parameter of this command is-s. The specific usage is:
Sudo ln-s source file target file

When we need to use the same file in different directories, we do not need to put a file that must be the same under every required directory, we only need to put the file in a fixed directory, and then use the ln command link in other directories to link it without occupying disk space repeatedly.
Example: sudo ln-s/usr/local/mysql/bin/mysqladmin/sbin/mysqladmin
-S indicates the symbol (symbolic.
If it is an executable file, we generally link it to the/sbin directory, so that you can directly enter the file name to execute the command without the directory address.
For example, in the preceding example, the following two statements are equivalent.
Yajiu @ yajiu-desktop :~ $ Mysqladmin-uroot-p password ubuntu
Yajiu @ yajiu-desktop :~ $/Usr/local/mysql/bin/mysqladmin-uroot-p password ubuntu

Note the following two points:
First, the ln command will keep the synchronization of each link file. That is to say, other files will change the same no matter which one you have changed;
Second, there are two types of ln links: Soft link and hard link. The soft link is ln-s *****. It will only generate a file image at your selected location, it does not occupy disk space. The hard link ln *** has no parameter-s. It will generate a file of the same size as the source file at the selected position, both soft links and hard links are synchronized.
If you use ls to view a directory, you will find an arrow in the upper-right corner of some files, that is, a file generated using ln command. You can use ls-l to view the file, the link path is displayed.

Syntax: ln [-bdfinsv] [-S <character tail backup string>] [-V <backup mode>] [-- help] [-- version] [source file or directory] [target file or directory] or ln [-bdfinsv] [-S <tail backup string>] [-V <backup mode>] [-- help] [-- version] [source file or directory...] [destination Directory]

Note: ln commands are used to connect files or directories. For example, if two or more files or directories are specified at the same time, and the last destination is an existing Directory, all the previously specified files or directories will be copied to this directory. If multiple files or directories are specified at the same time and the destination is not an existing Directory, an error message is displayed.

Parameters:
-B or -- backup # Delete, overwrite the backup before the target file
-D,-F, or -- directory # create a directory hard connection
-F or -- force # forcibly establish a connection to a file or directory, whether or not the file or directory exists
-I or -- interactive # ask the user before overwriting existing files
-N or -- no-dereference # treats the target directory of the symbolic connection as a general file
-S or -- symbolic # establishes a symbolic connection to the source file, instead of a hard connection.
-S <suffix backup string> or -- suffix = <suffix backup string> # use the "-B" parameter to back up the target file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.