V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
Tink
V2EX  ›  Linux

求大佬赐一个 Shell 脚本

  •  
  •   Tink · 2022-10-07 16:26:02 +08:00 · 2969 次点击
    这是一个创建于 538 天前的主题,其中的信息可能已经有所发展或是发生改变。

    功能是:

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

    感谢~

    第 1 条附言  ·  2022-10-07 20:10:40 +08:00
    9L 大佬给了脚本

    find . -type f -exec ls -l {} \;|tr -s " "|cut -d " " -f 2,9|grep -E "^1.*"|cut -d " " -f 2|xargs rm -f
    14 条回复    2022-10-09 21:16:39 +08:00
    filwaline
        1
    filwaline  
       2022-10-07 16:31:06 +08:00
    作业自己写(狗头.jpg)

    ---

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

    https://devhints.io/
    Tink
        2
    Tink  
    OP
       2022-10-07 16:32:04 +08:00
    不是作业,研究半天写不出来
    NoahNye
        3
    NoahNye  
       2022-10-07 16:39:47 +08:00
    find . -type l -exec ls -alh {} \;|awk '{if($2=1)print}'
    Tink
        4
    Tink  
    OP
       2022-10-07 16:44:04 +08:00
    @NoahNye #3 我试试,谢谢大佬!
    dorothyREN
        5
    dorothyREN  
       2022-10-07 16:51:04 +08:00
    awk 就能筛选出来,然后随便搞个 rm 就行了
    EvineDeng
        6
    EvineDeng  
       2022-10-07 17:30:35 +08:00
    是指找到没有被硬链接过的文件吗?
    cxtrinityy
        7
    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
        8
    cxtrinityy  
       2022-10-07 17:40:21 +08:00
    sorry, 忘了 grep inode 1 了, 自己中间加吧
    cxtrinityy
        9
    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
        10
    Tink  
    OP
       2022-10-07 20:10:08 +08:00
    @cxtrinityy #9 大佬你这个可以,牛逼!
    cattyhouse
        11
    cattyhouse  
       2022-10-08 05:48:22 +08:00 via iPhone
    find . -type f -inum 1 -exec rm {} +
    cattyhouse
        12
    cattyhouse  
       2022-10-08 06:03:14 +08:00 via iPhone
    find . -type f -links 1 -exec rm {} +
    echoechoin
        13
    echoechoin  
       2022-10-08 17:02:44 +08:00
    ltuxer
        14
    ltuxer  
       2022-10-09 21:16:39 +08:00
    12L 最简单
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1007 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 22:18 · PVG 06:18 · LAX 15:18 · JFK 18:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.