Created
January 6, 2012 13:53
-
-
Save henriquemoody/1570710 to your computer and use it in GitHub Desktop.
Find all occurrences of the files of DIR into other files and delete then
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HELP="Usage: $(basename ${0}) DIR | |
or: $(basename ${0}) --help | |
Find all occurrences of the files of DIR into other files and delete then if | |
there is no occurrence. | |
--help display this help and exit | |
Exemplos: | |
$(basename ${0}) web/images | |
$(basename ${0}) web/css | |
Report bugs to <fix@it.yourself>."; | |
if [ ! "${1}" ] | |
then | |
echo "${HELP}" 1>&2; | |
exit 1; | |
elif [ "${1}" == '--help' ] | |
then | |
echo "${HELP}"; | |
exit 0; | |
fi; | |
find "${1}" -name '*.*' | sort | while read filename; | |
do | |
basename=$(basename "${filename}"); | |
pattern=$(echo "${basename}" | sed 's/\./\\./g'); | |
occurrences=$(egrep -R "\b${pattern}\b" --include=*.* . | wc -l); | |
message="${basename} has ${occurrences} occurrences"; | |
if [ ${occurrences} -eq 0 ] | |
then | |
message="${message}: $(rm -fv ${filename})"; | |
fi; | |
echo "${message}"; | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment