Having trouble listing the contents of a folder I'm not in, while excluding the actual folder name itself.
ex:
root@vps [~]# find ~/test -type d
/root/test
/root/test/test1
However I want it to only display /test1, as the example.
Thoughts?
简单的没有错
find ~/test -mindepth 1
同样,这将产生相同的效果:
find ~/test/*
因为它匹配其中包含的所有内容,~/test/但不匹配~/test自身。
顺便说一句,您几乎肯定会发现find该选项会在任何其他开关之后抱怨-mindepth n,因为排序通常很重要,但-(min|max)depth n开关会影响整体行为。
你可以用-execand做到这一点basename:
find ~/test -type d -exec basename {} \;
解释:
find ~/test -type d部分递归地在 下查找所有目录。~/test-exec basename {} \;部件在basename上运行命令{},这是将最后一步的所有结果代入的位置。然后你需要-type f代替-type d.
或者,如果您想显示文件夹列表,不包括父文件夹-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初始文件夹名称在哪里。