|
使某工具成为系统默认命令行:
ln -s /yourpath/yourtool /sbin/yourtool
Linux之ln命令
一、介绍
ln命令用于将一个文件创建链接,链接分为软链接(类似于windows系统中的快捷方式)和硬链接(相当于对源文件copy,程序或命令对该文件block的另一个访问路口),命令默认使用硬链接。
二、使用方法
12语法:ln [选项][文件]选项:-s 对源文件创建软链接三、案例:
1.对文件创建软链接
123[root@ping ~]# ln -s /root/student.sql /root/db/ln.sql[root@ping ~]# ls -lh db/ln.sqllrwxrwxrwx 1 root root 17 2月 23 15:31 db/ln.sql -> /root/student.sql 2.对目录创建软链接
1234[root@ping ~]# ln -s db data[root@ping ~]# ll -h data/lrwxrwxrwx 1 root root 17 2月 23 15:31 ln.sql -> /root/student.sql[root@ping ~]# ln student.sql db/ 3.对文件创建硬链接
1234[root@ping ~]# ln student.sql db/[root@ping ~]# ls -lh db/lrwxrwxrwx 1 root root 17 2月 23 15:31 ln.sql -> /root/student.sql-rw-r--r-- 2 root root 2.9K 2月 12 10:17 student.sql三、软、硬链接说明
软链接:不可以删除源文件,删除源文件导致链接文件找不到,出现文件红色闪烁
硬链接:可以删除源文件,链接文件可以正常打开
Linux符号连接的层数过多的解决方法:
n创建符号链接的时候一定要使用绝对路径,
例如:
/usr/local/cxxt/config-tools
需要创建到 /usr/bin/config-tools
如果你当前目录在 cxxt目录下, 执行
ln -s ./config-tools /usr/bin/config-tools
这时候运行 config-tools
符号连接的层数过多
使用ln 命令使用绝对路径就可以了
ln -s /usr/local/cxxt/config-tools /usr/bin/config-tools
ln 命令
用途 : 链接文件。
语法
1>将某个文件链接到一个文件上
ln [ -f | -n] [ -s ] SourceFile [ TargetFile ]
2>将一个或多个文件链接到一个目录上
ln [ -f | -n] [ -s ] SourceFile … TargetDirectory
描述
ln 命令将在 SourceFile 参数中指定的文件链接到在 TargetFile 参数中指定的文件,或将其链接到在 TargetDirectory 参数中指定的另
一个目录中的文件。
在缺省情况下,ln 命令会创建硬链接。如果需要使用 ln 命令来创建符号链接,请指明 -s 标志。
|
|
|