简体   繁体   English

如何找到除.git目录下的目录以外的所有目录?

[英]How to find all directories except the ones under .git directory?

In my git repository I have a small directory structure under the root directory along with a very big directory structure under .git directory. 在我的git仓库中,我在根目录下有一个小的目录结构,在.git目录下有一个很大的目录结构。 I would like to use the find command to get a list of all directories under $(REPO_DIR) but not including any directory under $(REPO_DIR)/.git (including). 我想使用find命令来获取$(REPO_DIR)下所有目录的列表,但不包括$(REPO_DIR)/.git (包括)下的任何目录。 I tried something like 我尝试了类似的东西

find $(REPO_DIR) -type d ! -name ".git"

and

find $(REPO_DIR) -wholename ".git" -prune -type d

But unfortunately none worked as expected, any suggestions? 但是不幸的是,没有一个按预期工作,有什么建议吗?

Try: 尝试:

 find . -type d -not -iwholename '*.git*'

or: 要么:

find . -type d  -not -path './.git*'

As an alternative, if you're using bash, you could turn on extglob mode. 或者,如果您使用的是bash,则可以打开extglob模式。

shopt -s extglob

This would allow you to do (from within $(REPO_DIR) ): 这将允许您执行操作(在$(REPO_DIR) ):

find !(.git) -type d

See this answer for full details: https://stackoverflow.com/a/217017/24 有关完整的详细信息,请参见以下答案: https : //stackoverflow.com/a/217017/24

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何删除除与多个目录中的模式匹配的文件之外的所有文件 - How to remove all files except the ones that matches a pattern along several number of directories 如何编写将一个目录下的所有文件和目录复制到另一个目录的linux脚本? - How to write a linux script that copies all the files and directories under one directory to another directory? Linux-更改除1个目录以外的所有文件和目录的权限吗? - Linux - Change permissions of all files & directories except 1 directory? linux ksh如何删除除最新目录以外的所有目录 - linux ksh how to remove all directories except the latest some directories 如何正确使用“find ... -exec ...”来移动除少数文件和目录之外的所有文件和目录? - How to use "find ... -exec ..." correctly to move all files and directories except a few? 使用find - 删除除任何一个之外的所有文件/目录(在Linux中) - Using find - Deleting all files/directories (in Linux ) except any one 使用单个命令在所有目录下创建一个新目录:Linux - create a new directory under all directories using single command : Linux 如何获取文件系统下的所有目录 - how to get all directories under a file system Linux:如何删除文件夹中除具有特定名称的文件之外的所有文件? - Linux: how to remove all the files in a folder except ones with specific names? 如何在Docker容器中复制除任一目录之外的目录? - How to copy directories in docker container except any one directory?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM