Fork me on GitHub

N天学习一个Linux命令之ln

前言
有时候同一个文件想创建多个别名,这个时候可以使用链接文件代替

 

用途
对文件或者目录创建链接,默认创建的是硬链接

 

硬链接
Linux底层文件系统由超级数据块,目录树对象,inode索引节点对象,文件对象组成。硬链接指向同一个inode节点,可以理解为文件的别名,目录不能创建硬链接,不能跨文件系统创建硬链接。

 

软链接
软链接就是一个普通的文件,有自己的inode索引节点,只不过存储的内容比较特殊,存储的内容是指向的真实文件内容的访问路径,目标源不存在时也可以创建软链接。

 

常用参数
1.已存在链接备份
-b
--backup[=CONTROL]
1) 这2个选项都是备份,区别是--backup可以控制备份的行为
2) 备份行为说明
none, off 不备份
numbered, t 备份文件名按最大数字递增命名
existing, nil 存在即备份
simple, never 从不备份
2.指定备份文件名后缀,默认是~
-S, --suffix=SUFFIX
3.创建软链接
-s, --symbolic
4.其它
-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

实践
1.对目录test创建软链接t
[root@hlj_m_test01 tmp]# ln -s test t

 

后记
1.设备文件和socket文件不能创建软链接

 

参考资料
【1】理解 Linux 的硬链接与软链接
http://www.ibm.com/developerworks/cn/linux/l-cn-hardandsymb-links/index.html
【2】man ln

posted @ 2017-02-06 12:56  huan&ping  阅读(220)  评论(0编辑  收藏  举报