列出所有的linux子目录叶 [英] List all leaf subdirectories in linux

查看:128
本文介绍了列出所有的linux子目录叶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种简单的方法来列出Linux的指定目录下,只有目录?
为了更好地解释,我可以这样做:

 找到MYDIR型ð

这给:

  MYDIR / src目录
MYDIR / src目录/主
MYDIR /箱
MYDIR /斌/班

我想的却是:

  MYDIR / src目录/主
MYDIR /斌/班

我可以在遍历行并删除,如果下一行包含路径previous线bash脚本做到这一点,但我不知道是否有不使用bash的循环更简单的方法。


解决方案

 找到。型开发|排序| awk的'$ 0!〜最后的/{打印最后} {最后= $ 0} END {打印最后}

Is there an easy way to list only directories under a given directory in Linux? To explain better, I can do:

find mydir -type d

which gives:

mydir/src
mydir/src/main
mydir/bin
mydir/bin/classes

What I want instead is:

mydir/src/main
mydir/bin/classes

I can do this in a bash script that loops over the lines and removes previous line if next line contains the path, but I'm wondering if there is a simpler method that does not use bash loops.

解决方案

find . -type d | sort | awk '$0 !~ last "/" {print last} {last=$0} END {print last}'

这篇关于列出所有的linux子目录叶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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