求大佬赐一个 Shell 脚本

2022-10-07 16:26:02 +08:00
 Tink

功能是:

递归删除某一个文件夹下(有子文件和子文件夹)的所有 inode link ( iNode 链接数)等于 1 的文件

感谢~

3025 次点击
所在节点    Linux
14 条回复
filwaline
2022-10-07 16:31:06 +08:00
作业自己写(狗头.jpg)

---

给你个 cheatsheet ,查资料轻松一点

https://devhints.io/
Tink
2022-10-07 16:32:04 +08:00
不是作业,研究半天写不出来
NoahNye
2022-10-07 16:39:47 +08:00
find . -type l -exec ls -alh {} \;|awk '{if($2=1)print}'
Tink
2022-10-07 16:44:04 +08:00
@NoahNye #3 我试试,谢谢大佬!
dorothyREN
2022-10-07 16:51:04 +08:00
awk 就能筛选出来,然后随便搞个 rm 就行了
EvineDeng
2022-10-07 17:30:35 +08:00
是指找到没有被硬链接过的文件吗?
cxtrinityy
2022-10-07 17:39:21 +08:00
3L 那个只是找出来, 我来个完整的:
find . -type f -exec ls -l {} \;|tr -s " "|cut -d " " -f 9|xargs rm -f
cxtrinityy
2022-10-07 17:40:21 +08:00
sorry, 忘了 grep inode 1 了, 自己中间加吧
cxtrinityy
2022-10-07 17:42:09 +08:00
find . -type f -exec ls -l {} \;|tr -s " "|cut -d " " -f 2,9|grep -E "^1.*"|cut -d " " -f 2|xargs rm -f
Tink
2022-10-07 20:10:08 +08:00
@cxtrinityy #9 大佬你这个可以,牛逼!
cattyhouse
2022-10-08 05:48:22 +08:00
find . -type f -inum 1 -exec rm {} +
cattyhouse
2022-10-08 06:03:14 +08:00
find . -type f -links 1 -exec rm {} +
echoechoin
2022-10-08 17:02:44 +08:00
ltuxer
2022-10-09 21:16:39 +08:00
12L 最简单

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/885043

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX