[英]How can I make a bash script where I can move certain files to certain folders which are named based on a string in the files?
[英]How can I make shell script to recursively scan a directory and add certain files based on their name patterns to Git?
如何使 shell 腳本遞歸掃描克隆的 Git 目錄並根據名稱模式刪除某些文件? 如果文件滿足以下任一條件,
如果任何文件匹配,則應使用git rm </path/to/file/file name>
提前致謝。
使用find
進行掃描:
find . -regextype egrep \( -name .git -prune \) -o \
\( -type f -regex '.*(:[^/]*|[^/]{151,})$' -exec git rm '{}' \+ \)
(當然,先在沒有-exec
位的情況下進行試運行以確保它按預期工作)
注意:這假定 GNU find
,因為您標記了問題linux
。
這告訴find
跳過任何.git
子目錄,對於目錄樹中的所有其他常規文件,如果最后一個/
分隔的組件(文件名 + 擴展名,如果有)有冒號或 151 個或更多字符,則將其忽略到git rm
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.