一般情况下打包文件时,如果直接打包软连接会导致打包失败,即没有将要打包的内容打包进去,这里提供tar打包参数-h

[root@localhost ~]# ll /etc/rc.local

lrwxrwxrwx. 1 root root 13 Nov 24 00:45 /etc/rc.local -> rc.d/rc.local

[root@localhost ~]# tar czf tar.gz /etc/rc.local

tar: Removing leading `/' from member names

[root@localhost ~]# ll

[root@localhost ~]# sz tar.gz

rz

Starting zmodem transfer.  Press Ctrl+C to cancel.

  100%     117 bytes  117 bytes/s 00:00:01       0 Errors


[root@localhost ~]# 

wKiom1cMtKvhd76UAABkcTIMT5Y544.png

发现打包结果并没有将/etc/rc.local下的内容打包进来

所以这里用-h参数

[root@localhost ~]# tar czfh rc.local.tar.gz /etc/rc.local

tar: Removing leading `/' from member names

[root@localhost ~]# ll

total 84

-rw-------. 1 root root  1508 Nov 24 00:48 anaconda-ks.cfg

drwxr-xr-x. 5 root root  4096 Jun 10  2015 fabric-scripts

-rw-r--r--. 1 root root 17062 Dec 28 10:03 fabric-scripts.tar.gz

-rw-r--r--. 1 root root 33502 Nov 24 00:48 install.log

drwxr-xr-x. 2 root root  4096 Apr  7 15:08 logs

drwxr-xr-x. 3 root root  4096 Mar 23 10:35 mysql-sql

-rw-r--r--. 1 root root   415 Apr 12 16:42 rc.local.tar.gz

-rw-r--r--. 1 root root   117 Apr 12 16:31 tar.gz

[root@localhost ~]# sz rc.local.tar.gz 

rz

Starting zmodem transfer.  Press Ctrl+C to cancel.

  100%     415 bytes  415 bytes/s 00:00:01       0 Errors


[root@localhost ~]# 

wKioL1cMti6T1vQeAADGpIHf120130.png



[root@localhost ~]# tar xf rc.local.tar.gz 

[root@localhost ~]# ll

-rw-r--r--. 1 root root   415 Apr 12 16:42 rc.local.tar.gz

-rw-r--r--. 1 root root   117 Apr 12 16:31 tar.gz

[root@localhost ~]# cd etc/

[root@localhost etc]# ll

total 4

-rwxr-xr-x. 1 root root 420 Mar  8 14:36 rc.local

[root@localhost etc]# cat rc.local 

#!/bin/sh

#

# This script will be executed *after* all the other init scripts.

# You can put your own initialization stuff in here if you don't

# want to do the full Sys V style init stuff.


touch /var/lock/subsys/local

#startup Open*** on boot

/usr/local/sbin/open*** --config /etc/open***/product.server.conf &

#add a iptables ruler

/sbin/iptables -t nat -I POSTROUTING -s 10.8.0.0/255.255.255.0 -o eth0 -j MASQUERADE

[root@localhost etc]# 

至此,用tar打包软连接实际目录下内容操作成功