V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Shoestrong
V2EX  ›  程序员

Linux 用 ls 么

  •  
  •   Shoestrong · 2019-10-14 10:56:16 +08:00 · 5318 次点击
    这是一个创建于 1627 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

    ```
    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  
       2019-10-14 11:24:46 +08:00
    自己写一个 ls 的变种吧
    jmc891205
        15
    jmc891205  
       2019-10-14 11:25:25 +08:00
    ls 没有这样的功能
    要自己实现一个
    reus
        16
    reus  
       2019-10-14 11:29:37 +08:00
    你这标题和内容都不一致,不知道是语文没学好,还是问题没想清楚

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

    mac 的 ls 似乎支持用 ls -l@ 显示 xattr,不过 linux 主流的 ls 实现没有这个功能
    lilogo
        18
    lilogo  
       2019-10-14 11:49:13 +08:00
    不然呢? dir?
    zazalu
        19
    zazalu  
       2019-10-14 11:53:01 +08:00
    需要备注的话,ls 貌似没有的,你要自己整个 cli 工具! 可以魔改下 ls 的输出,把你的备注加上,但是备注信息你存在哪里呢- -?
    Rv8ex
        20
    Rv8ex  
       2019-10-14 11:53:55 +08:00
    一脸蒙
    krixaar
        21
    krixaar  
       2019-10-14 12:02:36 +08:00
    这是从 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  
       2019-10-14 12:04:05 +08:00
    伪需求。
    先不说做不做的出来,你弄这玩意目的是啥?文件夹名字不能体现其内容吗?莫不是你创建目录都是用 hash 命名的?
    sutra
        23
    sutra  
       2019-10-14 12:12:23 +08:00
    xattr
    loading
        24
    loading  
       2019-10-14 12:16:10 +08:00 via Android   ❤️ 2
    自己写个连备注数据库的 bin,自己完善备注。
    然后 alias。
    aliipay
        25
    aliipay  
       2019-10-14 12:30:33 +08:00
    @cominghome 有的,就是用的 hash
    ibreaker
        26
    ibreaker  
       2019-10-14 12:35:37 +08:00
    标题令人捉急
    oneisall8955
        27
    oneisall8955  
       2019-10-14 12:37:35 +08:00 via Android
    语义化没必要了吧,或者魔改一个读取文件夹下的 md 文件?
    jimmy2010
        28
    jimmy2010  
       2019-10-14 12:39:30 +08:00 via Android
    Windows 也没有这样的功能
    bumz
        29
    bumz  
       2019-10-14 12:58:50 +08:00 via iPhone
    你这是 XY Problem
    先说你遇到的问题,而不是你想的奇怪的解决方案
    cest
        30
    cest  
       2019-10-14 13:06:12 +08:00
    找有支持 descript.ion 的档案管理

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

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

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

    上次运维搞了一个 centos 精简版,killall 命令不支持,有点蛋疼
    bookit
        40
    bookit  
       2019-10-14 17:01:24 +08:00
    楼主看这个,The next gen ls command

    https://github.com/Peltoche/lsd

    文件夹直接显示个文件夹的小图标
    icris
        41
    icris  
       2019-10-14 17:07:33 +08:00
    Desktop 在 Finder 里显示桌面,还有一套复杂的操作给自己的文件夹添加本地化,建议觉得这个需求没有必要的学习一个(
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2025 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 16:16 · PVG 00:16 · LAX 09:16 · JFK 12:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.