linux 中实现仅仅列出软链接

 

001、借助ls -F

[root@pc1 test1]# ls           
aaa  a.txt  bbb  b.txt  c.txt  ddd  dir01  dir02  d.txt
[root@pc1 test1]# ll -h                       ## 测试目录
total 16K
lrwxrwxrwx. 1 root root   5 Dec 30 17:02 aaa -> a.txt
-rw-r--r--. 1 root root  21 Dec 30 17:01 a.txt
lrwxrwxrwx. 1 root root   5 Dec 30 17:02 bbb -> b.txt
-rw-r--r--. 1 root root 141 Dec 30 17:01 b.txt
-rw-r--r--. 1 root root 141 Dec 30 17:01 c.txt
lrwxrwxrwx. 1 root root   5 Dec 30 17:02 ddd -> d.txt
drwxr-xr-x. 2 root root   6 Dec 30 17:01 dir01
drwxr-xr-x. 2 root root   6 Dec 30 17:01 dir02
-rw-r--r--. 1 root root 141 Dec 30 17:01 d.txt
[root@pc1 test1]# ls -F | grep "@$"           ## 过滤出软链接文件
aaa@
bbb@
ddd@
[root@pc1 test1]# ls -F | grep "@$" | while read i; do echo $i; done    ## 写入循环迭代
aaa@
bbb@
ddd@

 

002、借助ll -h或者 ls -l

[root@pc1 test1]# ls
aaa  a.txt  bbb  b.txt  c.txt  ddd  dir01  dir02  d.txt
[root@pc1 test1]# ll -h
total 16K
lrwxrwxrwx. 1 root root   5 Dec 30 17:02 aaa -> a.txt
-rw-r--r--. 1 root root  21 Dec 30 17:01 a.txt
lrwxrwxrwx. 1 root root   5 Dec 30 17:02 bbb -> b.txt
-rw-r--r--. 1 root root 141 Dec 30 17:01 b.txt
-rw-r--r--. 1 root root 141 Dec 30 17:01 c.txt
lrwxrwxrwx. 1 root root   5 Dec 30 17:02 ddd -> d.txt
drwxr-xr-x. 2 root root   6 Dec 30 17:01 dir01
drwxr-xr-x. 2 root root   6 Dec 30 17:01 dir02
-rw-r--r--. 1 root root 141 Dec 30 17:01 d.txt
[root@pc1 test1]# ll -h | grep "^l"                          ## 软链接文件以l开头,借助grep过滤
lrwxrwxrwx. 1 root root   5 Dec 30 17:02 aaa -> a.txt
lrwxrwxrwx. 1 root root   5 Dec 30 17:02 bbb -> b.txt
lrwxrwxrwx. 1 root root   5 Dec 30 17:02 ddd -> d.txt
[root@pc1 test1]# ll -h | grep "^l" | awk '{print $NF}'      ## 输出文件名
a.txt
b.txt
d.txt

 。

 

003、借助find实现

[root@pc1 test1]# ls
aaa  a.txt  bbb  b.txt  c.txt  ddd  dir01  dir02  d.txt
[root@pc1 test1]# ll -h
total 16K
lrwxrwxrwx. 1 root root   5 Dec 30 17:02 aaa -> a.txt
-rw-r--r--. 1 root root  21 Dec 30 17:01 a.txt
lrwxrwxrwx. 1 root root   5 Dec 30 17:02 bbb -> b.txt
-rw-r--r--. 1 root root 141 Dec 30 17:01 b.txt
-rw-r--r--. 1 root root 141 Dec 30 17:01 c.txt
lrwxrwxrwx. 1 root root   5 Dec 30 17:02 ddd -> d.txt
drwxr-xr-x. 2 root root   6 Dec 30 17:01 dir01
drwxr-xr-x. 2 root root   6 Dec 30 17:01 dir02
-rw-r--r--. 1 root root 141 Dec 30 17:01 d.txt
[root@pc1 test1]# find ./ -type l              ## 借助find查找链接文件, -tyle l表示查找链接文件
./aaa
./bbb
./ddd
[root@pc1 test1]# find ./ -type l | cut -d "/" -f 2     ## 仅仅列出文件名
aaa
bbb
ddd

 。

 

posted @ 2023-12-30 10:41  小鲨鱼2018  阅读(20)  评论(0编辑  收藏  举报