kaisawind's blog
  • 关于
  • 所有帖子

ln -s(软链接)使用说明 - Tue, Jun 11, 2019

由于使用windows子系统,经常需要将windows的文件夹连接到linux的文件夹上,所以简单介绍下ln -s的使用方法。

  • 1. 概述
  • 2. 用法
    • 2.1 /bin/ln [OPTION]… [-T] TARGET LINK_NAME
    • 2.2 /bin/ln [OPTION]… TARGET
    • 2.3 /bin/ln [OPTION]… TARGET… DIRECTORY
    • 2.4 /bin/ln [OPTION]… -t DIRECTORY TARGET…
  • 3. 参数对应表
  • 4. 英文说明

1. 概述

Linux的ln命令是一个非常重要命令,它的功能是将一个文件在另外一个位置建立一个同步的链接。 一个地方修改,另一个地方也会同步的进行修改。

2. 用法

1. 默认创建硬链接,使用`-s`参数创建软链接
2. 默认每个要创建的链接都不应该存在
3. 当创建硬链接时,每个源目标必须存在。

2.1 /bin/ln [OPTION]… [-T] TARGET LINK_NAME

将源目标(TARGET)链接成LINK_NAME

2.2 /bin/ln [OPTION]… TARGET

在当前的文件夹创建与源目标(TARGET)相同名的链接

2.3 /bin/ln [OPTION]… TARGET… DIRECTORY

在文件夹DIRECTORY中为每个源目标TARGET创建链接

2.4 /bin/ln [OPTION]… -t DIRECTORY TARGET…

在文件夹DIRECTORY中为每个源目标TARGET创建链接

3. 参数对应表

shortlongdescription描述
–backup[=CONTROL]make a backup of each existing destination file备份每个现有目标文件
-blike –backup but does not accept an argument删除,覆盖以前建立的链接
-d,-F–directoryallow the superuser to attempt to hard link directories (note: will probably fail due to system restrictions, even for the superuser)允许超级用户制作目录的硬链接
-f–forceremove existing destination files强制执行
-i–interactiveprompt whether to remove destinations交互模式,文件存在则提示用户是否覆盖
-L–logicaldereference TARGETs that are symbolic links解除TARGETs软链接
-n–no-dereferencetreat LINK_NAME as a normal file if it is a symbolic link to a directory把符号链接视为一般目录
-P–physicalmake hard links directly to symbolic links将硬链接改为软链接
-r–relativecreate symbolic links relative to link location创建相对于链接位置的符号链接
-s–symbolicmake symbolic links instead of hard links软链接(符号链接)
-S–suffix=SUFFIXoverride the usual backup suffix字尾备份字符串
-t–target-directory=DIRECTORYspecify the DIRECTORY in which to create the links指定要在其中创建链接的文件夹
-T–no-target-directorytreat LINK_NAME as a normal file always始终将LINK_NAME视为普通文件
-v–verboseprint name of each linked file显示详细的处理过程
–helpdisplay this help and exit显示帮助信息
–versionoutput version information and exit显示版本信息

4. 英文说明

Usage: /bin/ln [OPTION]... [-T] TARGET LINK_NAME   (1st form)
  or:  /bin/ln [OPTION]... TARGET                  (2nd form)
  or:  /bin/ln [OPTION]... TARGET... DIRECTORY     (3rd form)
  or:  /bin/ln [OPTION]... -t DIRECTORY TARGET...  (4th form)
In the 1st form, create a link to TARGET with the name LINK_NAME.
In the 2nd form, create a link to TARGET in the current directory.
In the 3rd and 4th forms, create links to each TARGET in DIRECTORY.
Create hard links by default, symbolic links with --symbolic.
By default, each destination (name of new link) should not already exist.
When creating hard links, each TARGET must exist.  Symbolic links
can hold arbitrary text; if later resolved, a relative link is
interpreted in relation to its parent directory.

Mandatory arguments to long options are mandatory for short options too.
      --backup[=CONTROL]      make a backup of each existing destination file
  -b                          like --backup but does not accept an argument
  -d, -F, --directory         allow the superuser to attempt to hard link
                                directories (note: will probably fail due to
                                system restrictions, even for the superuser)
  -f, --force                 remove existing destination files
  -i, --interactive           prompt whether to remove destinations
  -L, --logical               dereference TARGETs that are symbolic links
  -n, --no-dereference        treat LINK_NAME as a normal file if
                                it is a symbolic link to a directory
  -P, --physical              make hard links directly to symbolic links
  -r, --relative              create symbolic links relative to link location
  -s, --symbolic              make symbolic links instead of hard links
  -S, --suffix=SUFFIX         override the usual backup suffix
  -t, --target-directory=DIRECTORY  specify the DIRECTORY in which to create
                                the links
  -T, --no-target-directory   treat LINK_NAME as a normal file always
  -v, --verbose               print name of each linked file
      --help     display this help and exit
      --version  output version information and exit

The backup suffix is '~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
The version control method may be selected via the --backup option or through
the VERSION_CONTROL environment variable.  Here are the values:

  none, off       never make backups (even if --backup is given)
  numbered, t     make numbered backups
  existing, nil   numbered if numbered backups exist, simple otherwise
  simple, never   always make simple backups

Using -s ignores -L and -P.  Otherwise, the last option specified controls
behavior when a TARGET is a symbolic link, defaulting to -P.

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Report ln translation bugs to <http://translationproject.org/team/>
Full documentation at: <http://www.gnu.org/software/coreutils/ln>
or available locally via: info '(coreutils) ln invocation'


辽ICP备2021007608号 | © 2025 | kaisawind

Facebook Twitter GitHub