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

求大佬赐一个 Shell 脚本

  •  
  •   Tink ·
    goxofy · Oct 7, 2022 · 4548 views
    This topic created in 1496 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
    filwaline
    Oct 7, 2022
    1
    作业自己写(狗头.jpg)

    ---

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

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