ln命令主要用于建立连接、软连接or硬连接。
参数:
-L, --logical:建立一个硬连接
-s, --symbolic:建立一个软连接(符号连接)
-d, -F, --directory:允许root建立文件夹硬连接,不过由于系统限制一般不允许
-f, --force:删除现有目标文件
-i, --interactive:提示用户是否删除目标文件 SourceByrd's Weblog-https://note.t4x.org/rebuilding/ln-command-description/
其他参数:SourceByrd's Weblog-https://note.t4x.org/rebuilding/ln-command-description/
-n, --no-dereference
note:treat destination that is a symlink to a directory as if it were a normal fileSourceByrd's Weblog-https://note.t4x.org/rebuilding/ln-command-description/--backup[=CONTROL]
note:make a backup of each existing destination fileSourceByrd's Weblog-https://note.t4x.org/rebuilding/ln-command-description/-b:like --backup but does not accept an argumentSourceByrd's Weblog-https://note.t4x.org/rebuilding/ln-command-description/
-S, --suffix=SUFFIX
note:override the usual backup suffixSourceByrd's Weblog-https://note.t4x.org/rebuilding/ln-command-description/-t, --target-directory=DIRECTORY
note:specify the DIRECTORY in which to create the linksSourceByrd's Weblog-https://note.t4x.org/rebuilding/ln-command-description/-T, --no-target-directory
note:treat LINK_NAME as a normal fileSourceByrd's Weblog-https://note.t4x.org/rebuilding/ln-command-description/-v, --verbose
note:print name of each linked file SourceByrd's Weblog-https://note.t4x.org/rebuilding/ln-command-description/
案例:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
[root@localhost abc]# ln -L dir abc #硬连接无法连接文件 ln: `dir': hard link not allowed for directory [root@localhost abc]# ln -d dir abc #尝试建立文件夹硬连接,但是系统不允许 ln: creating hard link `abc' => `dir': Operation not permitted [root@localhost abc]# ln -L 3 9 #硬连接文件,文件具有相同的inode号码 [root@localhost abc]# ll -hi total 12K 2491825 -rw-r--r--. 2 root root 4 Oct 9 14:17 3 2491826 -rw-r--r--. 1 root root 0 Oct 9 12:34 4 2491825 -rw-r--r--. 2 root root 4 Oct 9 14:17 9 [root@localhost abc]# ln -s dir abc #建立dir文件夹的软连接为abc文件 [root@localhost abc]# ll lrwxrwxrwx. 1 root root 3 Oct 9 14:21 abc -> dir drwxr-xr-x. 2 root root 4096 Oct 9 12:34 dir [root@localhost abc]# ln -i 3 10 #建立硬连接,-i要求用户是否确认覆盖 ln: replace `10'? y [root@localhost abc]# ln -f 3 10 #不进行提示,直接覆盖 [root@localhost abc]# ln -f 3 4 [root@localhost abc]# ll -hi total 20K 2491825 -rw-r--r--. 4 root root 4 Oct 9 14:17 10 2491825 -rw-r--r--. 4 root root 4 Oct 9 14:17 3 2491825 -rw-r--r--. 4 root root 4 Oct 9 14:17 4 2491825 -rw-r--r--. 4 root root 4 Oct 9 14:17 9 |