使用"*/"的任何理由在命令"ls -d */"中列出目录? [英] Any reason for using "*/" in command "ls -d */" to list directories?

查看:105
本文介绍了使用"*/"的任何理由在命令"ls -d */"中列出目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道还有其他一些方法可以做同样的事情,例如

I know there are some other ways to do the same thing, such as

ls -l | grep "^d"

ls -F | grep "/$"

我只是对在"ls -d"之后添加"*/"的原因感到好奇.为什么简单地使用"ls -d"不起作用?背后是否有任何故事或棘手的东西?

I am just curious about the reason for adding "*/" after "ls -d". Why simply using "ls -d" not work? Is there any story or tricky stuff behind it?

推荐答案

添加-d标志仅指示ls仅列出目录条目而不是目录内容.赋予ls*被扩展到当前目录中的所有条目,包括文件和目录.因此,ls -d *将列出此目录中的所有条目,而不扩展子目录.但是,如果使用*/,则bash会将其扩展为仅包括该目录中的目录.但是只要使用ls */,所有目录都将被扩展.添加-d标志可以防止这种情况,您只能在此目录中找到目录.

Adding the -d flag simply instructs ls to simply list directory entries rather than their contents. The * given to ls is expanded to all the entries in the current directory, both files and dirs. So ls -d * will list all entries in this directory, without expanding the subdirectories. But if you use */, then bash expands this to only include the directories in this directory. But with just ls */, all the directories will be expanded. Adding the -d flag prevents that, and you get just the directories in this directory.

这篇关于使用"*/"的任何理由在命令"ls -d */"中列出目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆