软连接ln

软连接ln

[root@even tmp]# 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.

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
-n, --no-dereference treat destination that is a symlink to a
directory as if it were a normal file
-i, --interactive prompt whether to remove destinations
-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 file before linking
--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 throughthe VERSION_CONTROL environment variable. Here are the values:`

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 bugs to <bug-coreutils@gnu.org>.

创建

ln -s [含有访问目标的文件或者目录] [自定义的软连接名称,可以是目录也可以是文件]

例子:/u01/testmount有脚本,有个程序需要访问这些脚本,但无法直接访问/u01/testmount

程序写死了只能访问/tmp目录,那么在/tmp下创建一个软连接,实际映射到/u01/testmount

[oracle@even testmount]$ pwd
/u01/testmount
[oracle@even testmount]$ ls -l
total 8
-rw-r--r-- 1 oracle oinstall 9 Jun 3 15:13 1.sh
-rw-r--r-- 1 oracle oinstall 6 Jun 3 15:13 2.sql
-rw-r--r-- 1 oracle oinstall 0 Jun 3 15:13 3.txt

[oracle@even testmount]$ **ln -s /u01/testmount /tmp/ln_access**
[oracle@even testmount]$ ll
total 8
-rw-r--r-- 1 oracle oinstall 9 Jun 3 15:13 1.sh
-rw-r--r-- 1 oracle oinstall 6 Jun 3 15:13 2.sql
-rw-r--r-- 1 oracle oinstall 0 Jun 3 15:13 3.txt
[oracle@even testmount]$ cd /tmp
[oracle@even tmp]$ ll
lrwxrwxrwx 1 oracle oinstall 14 Jun 3 16:16 ln_access -> /u01/testmount
[oracle@even tmp]$ cd ln_access
[oracle@even ln_access]$ ll
total 8
-rw-r--r-- 1 oracle oinstall 9 Jun 3 15:13 1.sh
-rw-r--r-- 1 oracle oinstall 6 Jun 3 15:13 2.sql
-rw-r--r-- 1 oracle oinstall 0 Jun 3 15:13 3.txt

压缩和解压

tar 打包默认不会备份目录下软连接指向的内容,需要加h参数,但要估算软连接指向的目录和文件的数据量。

定期对/tmp目录进行打包压缩然后清理

[root@even home]# tar -czvf tmp.tar.gz /tmp
tar: Removing leading `/’ from member names

[root@even home]# tar -tf tmp.tar.gz 发现安装包里没有软连接的内容
tmp/
tmp/hsperfdata_oracle/
tmp/hsperfdata_oracle/15778
tmp/hsperfdata_oracle/25244
tmp/hsperfdata_oracle/15849
tmp/hsperfdata_oracle/15713
tmp/.font-unix/
tmp/ln_access
tmp/.gdmDDWXH0
tmp/.X11-unix/
tmp/.X0-lock
tmp/gconfd-root/
tmp/gconfd-root/lock/
tmp/gconfd-root/lock/ior
tmp/.ICE-unix/
tmp/keyring-UyqNLP/
tmp/orbit-root/
tmp/orbit-root/bonobo-activation-register.lock
tmp/orbit-root/bonobo-activation-server-ior
tmp/keyring-UGeWOK/
tmp/ssh-yWwGqo3814/

打包时加上h参数解决软连接没有复制的情况,但如果软连接的目录是个海量目录就不建议了!!!

[root@even home]# tar -chzvf tmp.tar.gz /tmp

[root@even home]# tar -tf tmp.tar.gz
tmp/
tmp/hsperfdata_oracle/
tmp/hsperfdata_oracle/15778
tmp/hsperfdata_oracle/25244
tmp/hsperfdata_oracle/15849
tmp/hsperfdata_oracle/15713
tmp/.font-unix/
tmp/ln_access/
tmp/ln_access/2.sql
tmp/ln_access/1.sh
tmp/ln_access/3.txt
tmp/.gdmDDWXH0
tmp/.X11-unix/
tmp/.X0-lock
tmp/gconfd-root/
tmp/gconfd-root/lock/
tmp/gconfd-root/lock/ior
tmp/.ICE-unix/
tmp/keyring-UyqNLP/
tmp/orbit-root/
tmp/orbit-root/bonobo-activation-register.lock
tmp/orbit-root/bonobo-activation-server-ior
tmp/keyring-UGeWOK/
tmp/ssh-yWwGqo3814/

查找软连接

[root@even tmp]# ls -l|grep ^l
lrwxrwxrwx 1 oracle oinstall 14 Jun 3 16:16 ln_access -> /u01/testmount

[root@even /]# find /tmp -type l
/tmp/ln_access

删除软连接

进入查找到软连接的目录,利用rm -f当作文件删除即可

cd /tmp

rm -f ln_access

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值