Linux 用 ls 么

2019-10-14 10:56:16 +08:00
 Shoestrong

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

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

小括号中就是想要的效果
abcdabcd987
2019-10-14 11:20:28 +08:00
@Shoestrong ls -la
HENQIGUAI
2019-10-14 11:22:15 +08:00
没有就自定义 alias ll ->ls -la
scukmh
2019-10-14 11:23:43 +08:00
带颜色不就完了
Shoestrong
2019-10-14 11:23:45 +08:00
@abcdabcd987 @HENQIGUAI 这样并没有备注,需要自己自定义文件或文件夹备注
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
2019-10-14 11:24:46 +08:00
自己写一个 ls 的变种吧
jmc891205
2019-10-14 11:25:25 +08:00
ls 没有这样的功能
要自己实现一个
reus
2019-10-14 11:29:37 +08:00
你这标题和内容都不一致,不知道是语文没学好,还是问题没想清楚

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

mac 的 ls 似乎支持用 ls -l@ 显示 xattr,不过 linux 主流的 ls 实现没有这个功能
lilogo
2019-10-14 11:49:13 +08:00
不然呢? dir?
zazalu
2019-10-14 11:53:01 +08:00
需要备注的话,ls 貌似没有的,你要自己整个 cli 工具! 可以魔改下 ls 的输出,把你的备注加上,但是备注信息你存在哪里呢- -?
Rv8ex
2019-10-14 11:53:55 +08:00
一脸蒙

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/609069

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX