Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
Tink
V2EX  ›  Linux

求大佬赐一个 Shell 脚本

  •  
  •   Tink ·
    PRO
    ·
    goxofy · Oct 7, 2022 · 4125 views
    This topic created in 1319 days ago, the information mentioned may be changed or developed.

    功能是:

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

    感谢~

    Supplement 1  ·  Oct 7, 2022
    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 replies    2022-10-09 21:16:39 +08:00
    filwaline
        1
    filwaline  
       Oct 7, 2022
    作业自己写(狗头.jpg)

    ---

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

    https://devhints.io/
    Tink
        2
    Tink  
    OP
    PRO
       Oct 7, 2022
    不是作业,研究半天写不出来
    NoahNye
        3
    NoahNye  
       Oct 7, 2022
    find . -type l -exec ls -alh {} \;|awk '{if($2=1)print}'
    Tink
        4
    Tink  
    OP
    PRO
       Oct 7, 2022
    @NoahNye #3 我试试,谢谢大佬!
    dorothyREN
        5
    dorothyREN  
       Oct 7, 2022
    awk 就能筛选出来,然后随便搞个 rm 就行了
    EvineDeng
        6
    EvineDeng  
       Oct 7, 2022
    是指找到没有被硬链接过的文件吗?
    cxtrinityy
        7
    cxtrinityy  
       Oct 7, 2022
    3L 那个只是找出来, 我来个完整的:
    find . -type f -exec ls -l {} \;|tr -s " "|cut -d " " -f 9|xargs rm -f
    cxtrinityy
        8
    cxtrinityy  
       Oct 7, 2022
    sorry, 忘了 grep inode 1 了, 自己中间加吧
    cxtrinityy
        9
    cxtrinityy  
       Oct 7, 2022
    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
    PRO
       Oct 7, 2022
    @cxtrinityy #9 大佬你这个可以,牛逼!
    cattyhouse
        11
    cattyhouse  
       Oct 8, 2022 via iPhone
    find . -type f -inum 1 -exec rm {} +
    cattyhouse
        12
    cattyhouse  
       Oct 8, 2022 via iPhone
    find . -type f -links 1 -exec rm {} +
    echoechoin
        13
    echoechoin  
       Oct 8, 2022
    PeekPop
        14
    PeekPop  
       Oct 9, 2022
    12L 最简单
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5643 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 60ms · UTC 02:31 · PVG 10:31 · LAX 19:31 · JFK 22:31
    ♥ Do have faith in what you're doing.