Skip to content

Instantly share code, notes, and snippets.

@mattieb
Created October 8, 2022 20:57
Show Gist options
  • Save mattieb/bc63c20166abab35522187e445568cea to your computer and use it in GitHub Desktop.
Save mattieb/bc63c20166abab35522187e445568cea to your computer and use it in GitHub Desktop.
deletes files with the text " copy" in them if an original exists
#!/bin/sh
#
# Deletes files with the text " copy" in them if an original exists.
# Cleans up after me accidentally hitting duplicate across lots of
# nested folders.
#
if [ "x$1" == x ]
then
echo usage: $0 PATH >&2
exit 1
fi
find "$1" -name \*\ copy\* | (
while read copy
do
orig=$(echo ${copy} | sed -e 's/ copy//')
if [ -f "${orig}" ]
then
echo found orig for ${copy}
rm "${copy}"
else
echo no orig for ${copy}
fi
done
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment