How can I make shell script to recursively scan a cloned Git directory and remove certain files based on their name patterns? If the file meet any of the below condition,
If any of the file matches, it should be executed with git rm </path/to/file/file name>
Thanks in advance.
Use find
for the scanning:
find . -regextype egrep \( -name .git -prune \) -o \
\( -type f -regex '.*(:[^/]*|[^/]{151,})$' -exec git rm '{}' \+ \)
(Do a dry run without the -exec
bit first to make sure it works as desired, of course)
Note: This assumes GNU find
, since you tagged the question linux
.
This tells find
to skip any .git
subdirectories, and for all other regular files in the directory tree, if the last /
-separated component (The filename + extension if any) has a colon or 151 or more characters in it, pass it off to git rm
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.