在Bash中仅使用ls列出目录? [英] Listing only directories using ls in Bash?
问题描述
此命令列出当前路径中的目录: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屋!