shelll脚本,根据软链接,找到真实路径
# ls -ltotal 60520
lrwxrwxrwx 1 root root 11 Sep9 22:54 abc -> /etc/passwd
lrwxrwxrwx 1 root root 8 Sep9 23:02 cde -> /tmp/abc
lrwxrwxrwx 1 root root 8 Sep9 23:03 efg -> /tmp/cde
-rw-r--r-- 1 root root 206 Sep9 23:31 find_symfile.sh
drwx------ 2 root root 4096 Aug 182015 keyring-cmzNiY
srwxr-xr-x 1 root root 0 Aug6 14:54 mapping-root
-rw-r--r-- 1 root root 2323 Sep7 01:13 mysql-columns_priv-2016-09-07.sql
-rw-r--r-- 1 root root 3379 Sep7 01:13 mysql-db-2016-09-07.sql
-rw-r--r-- 1 root root 1972 Sep7 01:13 mysql-func-2016-09-07.sql
-rw-r--r-- 1 root root 3158 Sep7 01:13 mysql-help_category-2016-09-07.sql
-rw-r--r-- 1 root root 8443 Sep7 01:13 mysql-help_keyword-2016-09-07.sql
-rw-r--r-- 1 root root 9987 Sep7 01:13 mysql-help_relation-2016-09-07.sql
-rw-r--r-- 1 root root 405468 Sep7 01:13 mysql-help_topic-2016-09-07.sql
-rw-r--r-- 1 root root 3140 Sep7 01:13 mysql-host-2016-09-07.sql
-rw-r--r-- 1 root root 3189 Sep7 01:13 mysql-proc-2016-09-07.sql
-rw-r--r-- 1 root root 2409 Sep7 01:13 mysql-procs_priv-2016-09-07.sql
-rw-r--r-- 1 root root 2501 Sep7 01:13 mysql-tables_priv-2016-09-07.sql
-rw-r--r-- 1 root root 1883 Sep7 01:13 mysql-time_zone-2016-09-07.sql
-rw-r--r-- 1 root root 1957 Sep7 01:13 mysql-time_zone_leap_second-2016-09-07.sql
-rw-r--r-- 1 root root 1871 Sep7 01:13 mysql-time_zone_name-2016-09-07.sql
-rw-r--r-- 1 root root 2008 Sep7 01:13 mysql-time_zone_transition-2016-09-07.sql
-rw-r--r-- 1 root root 2150 Sep7 01:13 mysql-time_zone_transition_type-2016-09-07.sql
-rw-r--r-- 1 root root 5105 Sep7 01:13 mysql-user-2016-09-07.sql
-rw-r--r-- 1 root root 358 Sep7 01:13 table.log
drwxrwxrwt 2 root root 4096 Aug 20 16:06 VMwareDnD
drwxr-xr-x 2 root root 4096 Sep9 22:08 vmware-root
drwx------ 2 root root 4096 Sep6 21:06 vmware-root-1723735141
-r--r--r-- 1 root root 61260572 Aug 182015 VMwareTools-9.6.2-1688356.tar.gz
drwxr-xr-x 4 root root 4096 Mar 222014 vmware-tools-distrib
# bash find_symfile.shefg
/etc/passwd
# bash find_symfile.shcde
/etc/passwd
# bash find_symfile.shabc
/etc/passwd
# cat find_symfile.sh
#!/bin/bash
[[ $1 =~ ^/]] && a=$1 || a=`pwd`/$1
while [ -h $a ]
do
b=`ls -ld $a|awk '{print $NF}'`
c=`ls -ld $a|awk '{print $(NF-2)}'`
[[ $b =~ ^/ ]] && a=$b|| a=`dirname $c`/$b
done
echo $a
#
页:
[1]