[英]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.