[英]find folders in a directory, without listing the parent directory
列出我不在的文件夹的内容时遇到问题,同时排除实际的文件夹名称本身。
例如:
root@vps [~]# find ~/test -type d
/root/test
/root/test/test1
但是我希望它只显示/ test1,作为示例。
思考?
简单就没有错
find ~/test -mindepth 1
同样,这也会产生同样的效果:
find ~/test/*
因为它匹配~/test/
包含的所有内容,但不匹配~/test
本身。
-mindepth n
说一下,你几乎肯定会发现find
会抱怨-mindepth n
选项在任何其他开关之后,因为排序通常很重要但是-(min|max)depth n
开关会影响整体行为。
您可以使用-exec
和basename
:
find ~/test -type d -exec basename {} \;
说明:
find ~/test -type d
部分在~/test
下递归查找所有目录,如您所知。 -exec basename {} \\;
part在{}
上运行basename
命令,这是将最后一步的所有结果替换为的地方。 然后你需要-type f
而不是-type d
。
或者,如果要显示文件夹列表, -mindepth 1
包括父级-mindepth 1
( find ~/test -type d -mindepth 1
)。
现在你编辑了它,我想你想要的是什么
find ~/test -type d -mindepth 1 |cut -d/ -f3-
但我认为你需要更具体;-)
我只是用sed
修复它
find $BASE -type d \( ! -iname "." \)|sed s/$BASE//g
其中$BASE
是最初的foldername。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.