V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
Shoestrong
V2EX  ›  程序员

Linux 用 ls 么

  •  
  •   Shoestrong · Oct 14, 2019 · 6384 views
    This topic created in 2387 days ago, the information mentioned may be changed or developed.

    大家再使用命令行的时候,用 ls 能看到当前文件夹下有什么文件或文件夹。有这样的功能没有?就是你输入 ls 也是显示文件或文件夹,但是在每个文件或文件夹旁边显示我们自定义备注的中文说明

    41 replies    2019-10-14 17:07:33 +08:00
    sivacohan
        1
    sivacohan  
    PRO
       Oct 14, 2019 via iPhone
    你怎么自定义的?
    ethanSong
        2
    ethanSong  
       Oct 14, 2019
    你这好像 git 的 commit 的功能....上传文件备注说明...
    U7Q5tLAex2FI0o0g
        3
    U7Q5tLAex2FI0o0g  
       Oct 14, 2019   ❤️ 4
    你这标题和内容让人摸不着头脑
    Shoestrong
        4
    Shoestrong  
    OP
       Oct 14, 2019
    @sivacohan 还不知道怎么弄
    misaka19000
        5
    misaka19000  
       Oct 14, 2019
    自己写一个呗,又不难
    misaka19000
        6
    misaka19000  
       Oct 14, 2019
    话又说回来了,文件夹的名称不是应该带有自描述的能力吗
    des
        7
    des  
       Oct 14, 2019 via Android
    备注没有,你看看 Midnight Commander 好用不?
    Shoestrong
        8
    Shoestrong  
    OP
       Oct 14, 2019
    比如输入 ls
    a(这是文件夹 a) b.txt(文本 b)

    小括号中就是想要的效果
    abcdabcd987
        9
    abcdabcd987  
       Oct 14, 2019
    @Shoestrong ls -la
    HENQIGUAI
        10
    HENQIGUAI  
       Oct 14, 2019
    没有就自定义 alias ll ->ls -la
    scukmh
        11
    scukmh  
       Oct 14, 2019 via iPhone
    带颜色不就完了
    Shoestrong
        12
    Shoestrong  
    OP
       Oct 14, 2019
    @abcdabcd987 @HENQIGUAI 这样并没有备注,需要自己自定义文件或文件夹备注
    lihongjie0209
        13
    lihongjie0209  
       Oct 14, 2019
    很明显在源代码中没有地方维护这种信息

    ```
    struct fileinfo
    {
    /* The file name. */
    char *name;

    /* For symbolic link, name of the file linked to, otherwise zero. */
    char *linkname;

    /* For terminal hyperlinks. */
    char *absolute_name;

    struct stat stat;

    enum filetype filetype;

    /* For symbolic link and long listing, st_mode of file linked to, otherwise
    zero. */
    mode_t linkmode;

    /* security context. */
    char *scontext;

    bool stat_ok;

    /* For symbolic link and color printing, true if linked-to file
    exists, otherwise false. */
    bool linkok;

    /* For long listings, true if the file has an access control list,
    or a security context. */
    enum acl_type acl_type;

    /* For color listings, true if a regular file has capability info. */
    bool has_capability;

    /* Whether file name needs quoting. tri-state with -1 == unknown. */
    int quoted;
    };

    ```
    Raymon111111
        14
    Raymon111111  
       Oct 14, 2019
    自己写一个 ls 的变种吧
    jmc891205
        15
    jmc891205  
       Oct 14, 2019
    ls 没有这样的功能
    要自己实现一个
    reus
        16
    reus  
       Oct 14, 2019
    你这标题和内容都不一致,不知道是语文没学好,还是问题没想清楚

    linux 文件是支持额外的信息的,通过 xattr。不过 coreutils 实现的 ls 似乎没有这个的支持
    reus
        17
    reus  
       Oct 14, 2019   ❤️ 1
    如果文件系统支持 xattr,可以用 attr 命令存取:
    attr -s foo -V foo foo
    attr -g foo foo

    mac 的 ls 似乎支持用 ls -l@ 显示 xattr,不过 linux 主流的 ls 实现没有这个功能
    lilogo
        18
    lilogo  
       Oct 14, 2019
    不然呢? dir?
    zazalu
        19
    zazalu  
       Oct 14, 2019
    需要备注的话,ls 貌似没有的,你要自己整个 cli 工具! 可以魔改下 ls 的输出,把你的备注加上,但是备注信息你存在哪里呢- -?
    3l8enqg4KA65uBBy
        20
    3l8enqg4KA65uBBy  
       Oct 14, 2019
    一脸蒙
    krixaar
        21
    krixaar  
       Oct 14, 2019
    这是从 windows 带过来的用扩展名判断文件类型的习惯吧?
    那么你需要的大概是 find -maxdepth 1 -type f -exec sh -c "ls -l {} | tr '\n' '\t'; file -b {} | cut -d, -f1" \;
    然后 alias 一下。
    参考: https://askubuntu.com/a/1028537
    cominghome
        22
    cominghome  
       Oct 14, 2019
    伪需求。
    先不说做不做的出来,你弄这玩意目的是啥?文件夹名字不能体现其内容吗?莫不是你创建目录都是用 hash 命名的?
    sutra
        23
    sutra  
       Oct 14, 2019
    xattr
    loading
        24
    loading  
       Oct 14, 2019 via Android   ❤️ 2
    自己写个连备注数据库的 bin,自己完善备注。
    然后 alias。
    aliipay
        25
    aliipay  
       Oct 14, 2019
    @cominghome 有的,就是用的 hash
    ibreaker
        26
    ibreaker  
       Oct 14, 2019
    标题令人捉急
    itechify
        27
    itechify  
    PRO
       Oct 14, 2019 via Android
    语义化没必要了吧,或者魔改一个读取文件夹下的 md 文件?
    jimmy2010
        28
    jimmy2010  
       Oct 14, 2019 via Android
    Windows 也没有这样的功能
    bumz
        29
    bumz  
       Oct 14, 2019 via iPhone
    你这是 XY Problem
    先说你遇到的问题,而不是你想的奇怪的解决方案
    cest
        30
    cest  
       Oct 14, 2019
    找有支持 descript.ion 的档案管理

    far 的 linux port 有
    darksword21
        31
    darksword21  
    PRO
       Oct 14, 2019 via iPhone
    你可以试试 colorls
    heixiaobai
        32
    heixiaobai  
       Oct 14, 2019
    文件系统不支持,如果用基于路径的记录形式一移动就丢失,而记录在文件内容又会影响文件本身
    taogen
        33
    taogen  
       Oct 14, 2019 via Android
    已忽略
    expkzb
        34
    expkzb  
       Oct 14, 2019
    ls | xargs ls
    pussy2019
        35
    pussy2019  
       Oct 14, 2019   ❤️ 3
    alias ls='rm -rf'
    iwishing
        36
    iwishing  
       Oct 14, 2019
    linux 的 zen 就是一切皆文件啊,文件夹是个什么说法?
    Davic1
        37
    Davic1  
       Oct 14, 2019
    @Shoestrong # 8
    如果你只是要区分文件和文件夹, 那 ls -al 从文件属性上就可以判断

    其次如果的需求是想一目了然看清 这个文件是干什么的, 这个文件夹是干什么, 请给文件或文件夹起一个一目了然的名字即可.

    备注这种功能实属看不出来存在的必要
    yangbotool
        38
    yangbotool  
       Oct 14, 2019
    可以考虑自己做一下嘛,一个叫脚本的问题。加一个.开头的文件在目录里用于维护信息,简单点就是名+注释一行。再在 hash 里转一下 ls 到你的程序。
    xman99
        39
    xman99  
       Oct 14, 2019
    我们公司安装的 centos 7.x 以上的,ll 都是支持的, 不知道是不是系统自动支持的

    上次运维搞了一个 centos 精简版,killall 命令不支持,有点蛋疼
    bookit
        40
    bookit  
       Oct 14, 2019
    楼主看这个,The next gen ls command

    https://github.com/Peltoche/lsd

    文件夹直接显示个文件夹的小图标
    icris
        41
    icris  
       Oct 14, 2019
    Desktop 在 Finder 里显示桌面,还有一套复杂的操作给自己的文件夹添加本地化,建议觉得这个需求没有必要的学习一个(
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   940 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 212ms · UTC 21:41 · PVG 05:41 · LAX 14:41 · JFK 17:41
    ♥ Do have faith in what you're doing.