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?
You can do that with -exec
and basename
:
find ~/test -type d -exec basename {} \;
Explanation:
find ~/test -type d
part finds all directories recursively under ~/test
, as you already know.-exec basename {} \;
part runs the basename
command on {}
, which is where all the results from the last step are substituted into.