Listing only directories using ls in bash: An exam

2019-01-05 06:22发布

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

What exactly does the pattern */ do?

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?

25条回答
成全新的幸福
2楼-- · 2019-01-05 07:25

Adding on to make it full circle, to retrieve the path of every folder, use a combination of Albert's answer as well as Gordans that should be pretty usefull.

for i in $(ls -d /pathto/parent/folder/*/); do echo ${i%%/}; done

Output:

/pathto/parent/folder/childfolder1/
/pathto/parent/folder/childfolder2/
/pathto/parent/folder/childfolder3/
/pathto/parent/folder/childfolder4/
/pathto/parent/folder/childfolder5/
/pathto/parent/folder/childfolder6/
/pathto/parent/folder/childfolder7/
/pathto/parent/folder/childfolder8/
查看更多
登录 后发表回答