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

Posted 王月波

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shelll脚本,根据软链接,找到真实路径相关的知识,希望对你有一定的参考价值。

[[email protected] tmp]# ls -l 
total 60520
lrwxrwxrwx 1 root root       11 Sep  9 22:54 abc -> /etc/passwd
lrwxrwxrwx 1 root root        8 Sep  9 23:02 cde -> /tmp/abc
lrwxrwxrwx 1 root root        8 Sep  9 23:03 efg -> /tmp/cde
-rw-r--r-- 1 root root      206 Sep  9 23:31 find_symfile.sh
drwx------ 2 root root     4096 Aug 18  2015 keyring-cmzNiY
srwxr-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.log
drwxrwxrwt 2 root root     4096 Aug 20 16:06 VMwareDnD
drwxr-xr-x 2 root root     4096 Sep  9 22:08 vmware-root
drwx------ 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.gz
drwxr-xr-x 4 root root     4096 Mar 22  2014 vmware-tools-distrib
[[email protected] tmp]# bash find_symfile.sh  efg
/etc/passwd
[[email protected] tmp]# bash find_symfile.sh  cde
/etc/passwd
[[email protected] tmp]# bash find_symfile.sh  abc
/etc/passwd
[[email protected] tmp]# 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
[[email protected] tmp]# 

 

以上是关于shelll脚本,根据软链接,找到真实路径的主要内容,如果未能解决你的问题,请参考以下文章

软链接/硬链接

shelll脚本 for while until 循环

shelll函数数组告警系统需求分析

shelll脚本,常见的脚本题目。

012#构建shelll脚本库

012#构建shelll脚本库