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
。
分类:
linux shell
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!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全过程