Reputation: 83
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.
Upvotes: 0
Views: 221
Reputation: 52579
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
.
Upvotes: 4