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 @   小鲨鱼2018  阅读(25)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2021-12-30 R语言中判断两个数据框是否完全相同
2021-12-30 R语言中order排序出现2大于10的情况?
2021-12-30 R语言中NA的判断
2020-12-30 centos7 中 安装gcc编译器
2020-12-30 vmware虚拟机安装mint-20全过程
2020-12-30 vmware虚拟机安装deepin20全过程
2020-12-30 vmware虚拟机安装openSUSE-Leap-15.2全过程
点击右上角即可分享
微信分享提示