mkdir -p PDF for f in *.pdf ; do bn=$(basename -- "$f" .pdf) [ -e "$bn.doc" ] && mv -- "$f" PDF/ done I'll leave it up to you to rm -rf PDF/ - i like to leave the irrevocable step as late as possible in any potentially risky procedure.
If you prefer to just go ahead and delete them, then:
for f in *.pdf ; do [ -e "$(basename $f-- "$f" .pdf).doc" ] && rm -f -- "$f" done This version doesn't bother setting the intermediary variable "$bn" - either way works...the former is IMO more "readable" and is also better if you have any other uses for the file's basename. The former also deals better with filenames that spaces in them.