Linux命令--ln详解

基本作用

概括来说有两个作用:

1.为某一个目录在另外一个位置建立一个同步的链接,类似Windows下的超级链接;
2.为某一个文件创建一个软链接。

命令特点:

创建的软链接的内容与操作与原目录的一样。

命令参数

所有参数

使用ln –help命令查看一些ln命令的所有参数列表如下:

用法:ln [选项]... [-T] 目标 链接名   (第一种格式)
 或:ln [选项]... 目标        (第二种格式)
 或:ln [选项]... 目标... 目录  (第三种格式)
 或:ln [选项]... -t 目录 目标...   (第四种格式)
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.

必选参数对长短选项同时适用。
      --backup[=CONTROL]    为每个已存在的目标文件创建备份文件
  -b                类似--backup,但不接受任何参数
  -d, -F, --directory       创建指向目录的硬链接(只适用于超级用户)
  -f, --force           强行删除任何已存在的目标文件
  -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        显示此帮助信息并退出
      --version     显示版本信息并退出

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       不进行备份(即使使用了--backup 选项)
  numbered, t     备份文件加上数字进行排序
  existing, nil   若有数字的备份文件已经存在则使用数字,否则使用普通方式备份
  simple, never   永远使用普通方式备份

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/>
请向<http://translationproject.org/team/zh_CN.html> 报告ln 的翻译错误
Full documentation at: <http://www.gnu.org/software/coreutils/ln>
or available locally via: info '(coreutils) ln invocation'

常用参数解析

1.ln -s 
1.1 使用一:为文件创建软链接
ln -s filename1 filename2
1.2 使用二:为目录创建软链接
ln -s catalog1/catalog2 catalog1/catalog*
作用效果:创建的软链接的内容与操作与原目录的操作效果一样。
2.删除软链接
rm -rf catalog* **(注意不是rm -rf catalog*/**
rm -rf catelog*命令的效果:彻底删除该软链接了;
rm -rf catalog*命令的效果:只是删除了该软链接下的内容,但是该软链接仍然存在。

待解决

为什么删除软链接不能使用命令:rm -rf catalog*/。

参考资料

http://www.cnblogs.com/micky-zhou/archive/2012/08/01/2618203.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值