首页 > 代码库 > shelll脚本,根据软链接,找到真实路径

shelll脚本,根据软链接,找到真实路径

[root@localhost tmp]# ls -l total 60520lrwxrwxrwx 1 root root       11 Sep  9 22:54 abc -> /etc/passwdlrwxrwxrwx 1 root root        8 Sep  9 23:02 cde -> /tmp/abclrwxrwxrwx 1 root root        8 Sep  9 23:03 efg -> /tmp/cde-rw-r--r-- 1 root root      206 Sep  9 23:31 find_symfile.shdrwx------ 2 root root     4096 Aug 18  2015 keyring-cmzNiYsrwxr-xr-x 1 root root        0 Aug  6 14:54 mapping-root-rw-r--r-- 1 root root     2323 Sep  7 01:13 mysql-columns_priv-2016-09-07.sql-rw-r--r-- 1 root root     3379 Sep  7 01:13 mysql-db-2016-09-07.sql-rw-r--r-- 1 root root     1972 Sep  7 01:13 mysql-func-2016-09-07.sql-rw-r--r-- 1 root root     3158 Sep  7 01:13 mysql-help_category-2016-09-07.sql-rw-r--r-- 1 root root     8443 Sep  7 01:13 mysql-help_keyword-2016-09-07.sql-rw-r--r-- 1 root root     9987 Sep  7 01:13 mysql-help_relation-2016-09-07.sql-rw-r--r-- 1 root root   405468 Sep  7 01:13 mysql-help_topic-2016-09-07.sql-rw-r--r-- 1 root root     3140 Sep  7 01:13 mysql-host-2016-09-07.sql-rw-r--r-- 1 root root     3189 Sep  7 01:13 mysql-proc-2016-09-07.sql-rw-r--r-- 1 root root     2409 Sep  7 01:13 mysql-procs_priv-2016-09-07.sql-rw-r--r-- 1 root root     2501 Sep  7 01:13 mysql-tables_priv-2016-09-07.sql-rw-r--r-- 1 root root     1883 Sep  7 01:13 mysql-time_zone-2016-09-07.sql-rw-r--r-- 1 root root     1957 Sep  7 01:13 mysql-time_zone_leap_second-2016-09-07.sql-rw-r--r-- 1 root root     1871 Sep  7 01:13 mysql-time_zone_name-2016-09-07.sql-rw-r--r-- 1 root root     2008 Sep  7 01:13 mysql-time_zone_transition-2016-09-07.sql-rw-r--r-- 1 root root     2150 Sep  7 01:13 mysql-time_zone_transition_type-2016-09-07.sql-rw-r--r-- 1 root root     5105 Sep  7 01:13 mysql-user-2016-09-07.sql-rw-r--r-- 1 root root      358 Sep  7 01:13 table.logdrwxrwxrwt 2 root root     4096 Aug 20 16:06 VMwareDnDdrwxr-xr-x 2 root root     4096 Sep  9 22:08 vmware-rootdrwx------ 2 root root     4096 Sep  6 21:06 vmware-root-1723735141-r--r--r-- 1 root root 61260572 Aug 18  2015 VMwareTools-9.6.2-1688356.tar.gzdrwxr-xr-x 4 root root     4096 Mar 22  2014 vmware-tools-distrib[root@localhost tmp]# bash find_symfile.sh  efg/etc/passwd[root@localhost tmp]# bash find_symfile.sh  cde/etc/passwd[root@localhost tmp]# bash find_symfile.sh  abc/etc/passwd[root@localhost tmp]# cat find_symfile.sh #!/bin/bash[[ $1 =~ ^/  ]] && a=$1 || a=`pwd`/$1while [ -h $a ]do   b=`ls -ld $a|awk {print $NF}`   c=`ls -ld $a|awk {print $(NF-2)}`   [[ $b =~ ^/ ]] && a=$b  || a=`dirname $c`/$bdoneecho $a[root@localhost tmp]# 

 

shelll脚本,根据软链接,找到真实路径