• 请不要在回答技术问题时复制粘贴 AI 生成的内容
hwdq0012
V2EX  ›  程序员

zsh 的 file 工具和 Linux 自带 file 相比,还比较含蓄了

  •  
  •   hwdq0012 ·
    nocanstillbb · Aug 24, 2025 · 3673 views
    This topic created in 272 days ago, the information mentioned may be changed or developed.
    rn/minesweeper/libs
    ✦ ❯ touch a
    
    rn/minesweeper/libs
    ✦ ❯ ln -s a b
    
    rn/minesweeper/libs
    ✦ ❯ ll
    total 0
    -rw-r--r--  1 hbb  staff     0B  8 24 16:29 a
    lrwxr-xr-x  1 hbb  staff     1B  8 24 16:29 b -> a
    
    rn/minesweeper/libs
    ✦ ❯ file b
    b: empty
    

    不会提示是一个链接符号

    刚才 file 看了输出正常就 rm -rf 了

    在 linux 下 file 如果是链接符号 会提示一下

    $ mkdir test
    $ touch a 
    $ ln -s a b
    $ file b
    b: symbolic link to a
    
    

    .git 都干没了

    10 replies    2025-08-25 19:11:14 +08:00
    aloxaf
        1
    aloxaf  
       Aug 24, 2025
    zsh 没有内置的 file 命令吧?
    hwdq0012
        2
    hwdq0012  
    OP
       Aug 24, 2025
    @aloxaf #1 应该是 mac 的, 还有 du 都和 Linux 不一样
    chingyat
        3
    chingyat  
       Aug 24, 2025 via iPhone
    GNU 的命令行工具大多比 BSD 的好用
    w568w
        4
    w568w  
       Aug 24, 2025
    macOS 的实现: https://github.com/apple-oss-distributions/file/blob/03da74dd39d8209bfe953306347a8c514e688025/file/src/fsmagic.c#L383

    Linux 的(上游的)实现: https://github.com/file/file/blob/74e451be9d9e86af5e06e9795403017f8c6833ba/src/fsmagic.c#L375

    没看出太大区别。两边应该都会打印符号链接。是版本问题?

    另外不该依赖这个看符号链接的。
    cnbatch
        5
    cnbatch  
       Aug 24, 2025
    @chingyat 是 mac 的命令行工具版本太旧了
    skiy
        6
    skiy  
       Aug 24, 2025
    zsh 没有内置 file 命令。
    macos 中的很多命令跟 linux 的都有差别。比如 sed -i 就不一样。
    cnbatch
        7
    cnbatch  
       Aug 24, 2025
    mac 的内置命令行工具应该很久都没更新过了,上游的工具都早已迭代了很多个版本

    FreeBSD 的输出:
    b: symbolic link to a

    NetBSD 的输出:
    b: symbolic link to a

    OpenBSD 的输出:
    b: symbolic link to 'a'
    hwdq0012
        8
    hwdq0012  
    OP
       Aug 24, 2025 via iPhone
    @w568w ls -l 准吗
    hwdq0012
        9
    hwdq0012  
    OP
       Aug 24, 2025 via iPhone
    @skiy ps 也不一样 mac 参数前不➕-
    bao3
        10
    bao3  
       Aug 25, 2025
    @hwdq0012 其实 linux 的 ps 也不加 - 。还有 tar 等等。 这些都是古早的工具遗留下来的。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2790 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 10:17 · PVG 18:17 · LAX 03:17 · JFK 06:17
    ♥ Do have faith in what you're doing.