One day a shell command Linux file Operation series-LN command detailed _linux Shell

Source: Internet
Author: User
Tags directory create parent directory advantage

In the hint: many of the translation of Ubuntu is literal literal translation, there are many problems, so I suggest you refer to my explanation here. Of course, it was also some of the suspicion of the text, I hope.

Often operate on Linux, have a few fixed commands in different directories, or modify a few fixed files, this time, if you can operate them in a directory, it will be a very easy thing. Let's take a look at the link command Ln

Name

The ln full name is link as the name suggests, this is a link to create a. How to understand it? It functions like an alias to Mac OS or a shortcut to Windows, and deletion does not affect the file itself.

Description: (Take a look at the italic directly, it's OK)

Links can be divided into two types: Hard link (hard link) and soft link (symbolic link),

Both types of links provide a means of bidirectional referencing-that is to say, whether you use the name of the file to modify the contents of the file, your modified effect will be reflected to the original name of the file, will also reflect the link name of the file. When you are working at a higher level, the difference between soft and hard links occurs. Hard Chain
The advantage is that the original file and the linked file are independent of each other-if you delete or rename old files, then this action will not affect the hard linked file, the hard linked file or the contents of the original file.
However, if you use a soft link, when you delete or rename the old file, the soft link will no longer find the contents of the original file. The advantage of a soft link is that it spans the file system (because it's just a reference to the filename, not the real data). Another difference with hard links is that a symbolic link can point to a
Directory.

Example:

1. $LN file.txt file.copy

File.Copy is a shortcut to file.txt.

View-help

Copy Code code as follows:

Usage: ln [options] ... [-t] destination link name (first form)
Or: ln [options] ... Target (second format)
Or: ln [options] ... Goal... Table of contents (third format)
Or: ln [options] ...-t directory target ... (Fourth form)
In the first format, create the specified name and point to the specified destination link.
In the second format, create a link to the target location in the current directory.
In the third to fourth format, create a link to the specified destination in the specified directory.
Create a hard link by default and create a symbolic link when using--symbolic.
Each specified target must exist when a hard link is created. A symbolic link can point to any location,
Resolves a link that is associated with its parent directory when the link is resolved correctly.
Parameters that must be used for long options are also required for short options.
--backup[=control] Creates a backup file for each existing target file
-B is similar to--backup, but does not accept any parameters
-D,-F,--directory create a hard link to the directory (for Superuser only)
-F,--force forcibly overwrite any existing linked files
-I,--interactive to overwrite the linked file before confirming
-L,--logical creates a hard link as a symbolic link reference
-N,--no-dereference if the destination is a link to a symbolic link to a directory, the
The symbolic link is treated as a normal file, and the existing chain is first
Back up or overwrite
-S,--symbolic create Symbolic links (soft links) instead of hard links
-S,--suffix= suffix to specify the suffix of the linked file
-T, the--target-directory= directory creates links in the specified directory
-T,--no-target-directory the link name as a normal file
-V, printing related information before--verbose links

--HELP displays this help information and exits
--version display version information and exit

The suffix of the backup file is "~" unless the--suffix option or the Simple_backup_suffix
environment variable specified. Versioning can be done through the--backup option or the Version_control environment
Variable to select. The following are the available variable values:

Use the-S option ignores-l and-P.
Otherwise, when the source is a symbolic link (default-p), the behavior is controlled by an option that is last specified.

None, off no backup (even with the--backup option)
Numbered, t backup files plus numbers to sort
Existing, nil if a digital backup file already exists, use a number, or use a normal way to back up
Simple, never always use normal way to back up

Interpretation:

1-S

Create a soft link ln-s file.txt/${dir}/file.copy

2.-f-b

-F is actually a forced overwrite of existing hard links (note: Some Ubuntu translations are incorrect)

-B refers to pre-overwrite backup

3.–i

Ask questions before overwriting files

4.–s

There is an essential difference with-S. Here is the suffix name (which may be called an extension in window, but not in Linux to distinguish files in this way)

Actual combat:

1. Now I need to configure JDK,TOMCAT, and there are multiple nodes, and some of the configuration files in different directories. Sometimes, some remote toolset is used. The work time is a little long, slowly find a lot of time in the switching directory, so I put all the shortcuts, all the set of several folders, and to classify, and then some simple operation with remote or shared, under win operation.

2. Establish Soft Links

$LN –s file.txt/${dir}/

3. Can be prompted by the suffix name of the file is a soft connection

$ln –s file.txt/${dir}/file-v-s.url

-V Prompt file changes,-s.url represents the suffix name of file-S indicates a soft connection

4. If you always encounter many similar names, you need to be prompted before overwriting

Do not prompt before $ln-F overlay
$LN-I tip before overwriting

About Chinese

Usage: ln [options] ... [-T] Target link name (first format) or: ln [options] ... Target (second format) or: ln [options] ... Goal...	Table of contents (third format) or: ln [options] ...-t directory target ...
(fourth format) in the first format, create the specified name and point to the specified destination link.
In the second format, create a link to the target location in the current directory.
In the third to fourth format, create a link to the specified destination in the specified directory.
Create a hard link by default and create a symbolic link when using--symbolic. Each specified target must exist when a hard link is created.

A symbolic link can point to any location, resolving it to a link that is associated with its parent directory when the link is parsed correctly.
   Parameters that must be used for long options are also required for short options.			--backup[=control] Creates a backup file for each existing target file-B similar to--backup, but does not accept any arguments-D, F,--directory create a hard link to the directory (for Superuser only)-F,--force
				Forcibly delete any existing target file-I,--interactive before deleting the file-L,--logical to create a hard link as a symbolic link reference-N,--no-dereference if the destination is a symbolic link to a directory, the 	The symbolic link is treated as a normal file, the existing link is first backed up or deleted-S,--symbolic to create the symbolic link instead of the hard link-s, the--suffix= suffix specifies the suffix of the backup file-T,--target-directory= directory Create a link in the specified directory-T,--no-target-directory the link name as a normal file-V,--verbose the name of each file before linking--help display this help information and exit--version display version letter The suffix of the backup file is "~" unless specified with the--suffix option or the SIMPLE_BACKUP_SUFFIX environment variable. Versioning can be selected through the--backup option or version_control environment variable.
The following are the available variable values: Using the-s option ignores-l and-P.

 Otherwise, when the source is a symbolic link (default-p), the behavior is controlled by an option that is last specified. NoNE, off do not backup (even if the--backup option is used) numbered, t backup files plus numbers to sort existing, nil if there is a number of backup files already exist then use a number, otherwise use normal way to back up simple, neve R always back up with normal mode

Related Article

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.