【发布时间】:2022-01-05 15:00:09
【问题描述】:
我需要获取作为 git 存储库的目录的内容数。
我必须得到:
1) Other directories inside the directory I am currently iterating (and the other sub-directories inside them if they exist)
2) .txt files inside the directory and its sub-directories
3) All the non-txt files inside the directory and its sub-directories
在上述所有情况下,我必须忽略 .git 目录,以及其中的所有文件和目录。
我还必须专门使用 bash 脚本。我无法使用其他编程语言。
现在我正在使用以下命令来实现这一点:
-
要获取我使用的所有
.txt文件:find . -type f \( -name "*.txt" \)。.git中没有.txt文件,所以这是可行的。 -
要获取我使用的所有
non-txt文件:find . -type f \( ! -name "*.txt" \)。问题是我还从.git获取了所有文件,我不知道如何忽略它们。 -
要获取所有
directories和sub-directories,我使用:find . -type d。我不知道如何忽略.git目录及其子目录
【问题讨论】: