有没有办法添加可以在 ls 输出(或 ls 的替代方案)中查看的“描述”字段/元数据?

有没有办法添加可以在 ls 输出(或 ls 的替代方案)中查看的“描述”字段/元数据?

我一生的大部分时间都在使用 UNIX 系统。我经常发现自己在向别人传授这些知识。我收到很多问题,例如“该/etc文件夹的用途是什么?”来自学生,有时我自己也有同样的问题。我知道所有信息都可以通过简单的谷歌搜索获得,但我想知道是否有任何工具或解决方案能够向可以轻松从命令行查看的文件夹(和/或文件)添加描述?这基本上可以是一个选项ls或一个执行类似操作的程序。

  • 我希望有这样的事情:
    $ ls-alt --show-descriptions /
    ...
    /etc – Configuration Files
    /opt – Optional Software
    /bin - Binaries
    /sbin – System Binaries
    /tmp – Temporary Files
    ...
    
  • 甚至可以更进一步并提供详细的描述选项:
    $ ls-alt --show-descriptions-verbose /
    ...
    /etc – The /etc directory contains the core configuration files of the system, use primarily by the administrator and services, such as the password file and networking files.
    /opt – Traditionally, the /opt directory is used for installing/storing the files of third-party applications that are not available from the distribution’s repository.
    /bin - The ‘/bin’ directly contains the executable files of many basic shell commands like ls, cp, cd etc. Mostly the programs are in binary format here and accessible by all the users in the Linux system.
    /sbin – This is similar to the /bin directory. The only difference is that is contains the binaries that can only be run by root or a sudo user. You can think of the ‘s’ in ‘sbin’ as super or sudo.
    /tmp – This directory holds temporary files. Many applications use this directory to store temporary files. /tmp directories are deleted when your system restarts.
    ...
    

我知道没有默认方法可以使用 执行此操作ls,并且添加这样的功能可能需要大量重写内核代码以考虑存储的附加数据,所以我不是问如何执行此操作本质上是必然的(除非有一个我忽略的简单方法)。我更多地问是否有一个用于教育目的的工具已经存在,可以实现此类功能?我想它会从中获取输出ls,然后进行查找以将目录名称与它已经保存在某处的描述相匹配,但我离题了。

答案1

tree --info会做你想做的事。

您可以创建.info包含您的评论的 txt 文件

  • 某些文件和文件夹
  • 或文件和文件夹组(使用通配符)。

tree --info然后将在目录列表中显示它们。

可以进行多行注释。

其中还有一个全局信息文件,其中/usr/share/finfo/global_info包含 Linux 文件系统的说明(请参阅这里)。该文件还可以轻松地向您展示.info文件语法的外观。

该软件的主页是https://fossies.org/linux/misc/tree-2.1.1.tgz/

答案2

现代文件系统(包括ext*系列)能够为文件创建扩展属性。它们可以通过xattr工具进行管理

# set a comment
xattr -w user.comment "The cool file" file
# analogue to ls with comments
xattr -p user.comment *

唯一的限制是文件的所有附加属性(包括文件名本身)都应该适合 FS 的页面。但如今这并不是一个真正的问题。

据我所知,根本ls不读取扩展属性。

另外,如果您对指挥官风格的文件管理器感兴趣:Linux 版本的FAR Manager(far2l) 可与Descript.ionfiles.bbs文件一起使用。在这两种情况下,它只是一种name description文件格式。

有传言说它Midnight Commander也能够处理这些desript.ion文件,但我不确定如何操作。

相关内容