在Bash中仅使用ls列出目录? [英] Listing only directories using ls in Bash?

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

问题描述

此命令列出当前路径中的目录:ls -d */

This command lists directories in the current path: ls -d */

图案*/的确切作用是什么?

What exactly does the pattern */ do?

我们如何在上述命令(例如ls -d /home/alice/Documents)中给出绝对路径,以便仅列出该路径中的目录?

And how can we give the absolute path in the above command (e.g. ls -d /home/alice/Documents) for listing only directories in that path?

推荐答案

*/是一种匹配当前目录中所有子目录的模式(*将匹配所有文件子目录; /将其限制为目录).同样,要列出/home/alice/Documents下的所有子目录,请使用ls -d /home/alice/Documents/*/

*/ is a pattern that matches all of the subdirectories in the current directory (* would match all files and subdirectories; the / restricts it to directories). Similarly, to list all subdirectories under /home/alice/Documents, use ls -d /home/alice/Documents/*/

这篇关于在Bash中仅使用ls列出目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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