在 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屋!