Nemo

Nemo 关注TA

路漫漫其修远兮,吾将上下而求索。

Nemo

Nemo

关注TA

路漫漫其修远兮,吾将上下而求索。

  •  普罗旺斯
  • 负责帅就完事了
  • 写了1,496,113字

该文章投稿至Nemo社区   Linux  板块 复制链接


linux下建立软连接:ln

发布于 2017/11/20 15:59 3,005浏览 0回复 3,494

其中/home/nemo/source_ln 就是源文件,/home/nemo/test_ln建立连接的目标位置,其作用是当进入/home/nemo/test_ln目录或者操作/home/nemo/test_ln文件,实际上是链接进入/操作了/home/nemo/source_ln

先举个栗子:

ln -s /home/nemo/source_ln  /home/nemo/test_ln


linux下的软链接类似于windows下的快捷方式

如上面的栗子,当我们执行命令 

 cd /home/nemo/test_ln

的时候  实际上是进入了 /home/nemo/source_ln目录。

值得注意的是执行命令的时候,应该是/home/nemo/source_ln目录/文件已经存在,目录/文件 /home/nemo/test_ln是不存在的。如果后者已经存在,那么在建立软连接的时候则会返回异常。

选项 -s :s 貌似是指symbolic,说明需要建立软连接。相对的,如果没有该参数,默认则会建立硬连接。

硬连接相当于把源目录的文件全部都拷贝一份到目标目录。(我猜)


删除软链接:

rm -rf /home/nemo/test_ln #注意不是rm -rf /home/nemo/test_ln/

 

具体的ln命令文档说明如下:

nemo@echo:~/b$ ln --help
Usage: ln [OPTION]... [-T] TARGET LINK_NAME   (1st form)
  or:  ln [OPTION]... TARGET                  (2nd form)
  or:  ln [OPTION]... TARGET... DIRECTORY     (3rd form)
  or:  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.
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               make hard links to symbolic link references
  -n, --no-dereference        treat destination that is a symlink to a
                                directory as if it were a normal file
  -P, --physical              make hard links directly to symbolic links
  -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
  -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:

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

  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

Report ln bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'ln invocation'
本文标签
 {{tag}}
点了个评