svn status --no-ignore | grep '^[I?]' | cut -c 9- | while IFS= read -r f; do rm -rf "$f"; done
This has the following features:
- Both ignored and untracked files are deleted
- It works even if a file name contains whitespace (except for newline, but there's not much that can be done about that other than use the
--xml
option and parse the resulting xml output)
- It works even if
svn status
prints other status characters before the file name (which it shouldn't because the files are not tracked, but just in case...)
- It should work on any POSIX-compliant system
I use a shell script named svnclean
that contains the following:
#!/bin/sh
# make sure this script exits with a non-zero return value if the
# current directory is not in a svn working directory
svn info >/dev/null || exit 1
svn status --no-ignore | grep '^[I?]' | cut -c 9- |
# setting IFS to the empty string ensures that any leading or
# trailing whitespace is not trimmed from the filename
while IFS= read -r f; do
# tell the user which file is being deleted. use printf
# instead of echo because different implementations of echo do
# different things if the arguments begin with hyphens or
# contain backslashes; the behavior of printf is consistent
printf '%s
' "Deleting ${f}..."
# if rm -rf can't delete the file, something is wrong so bail
rm -rf "${f}" || exit 1
done
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…