Skip to main content
missing quote and --
Source Link
Stéphane Chazelas
  • 586.2k
  • 96
  • 1.1k
  • 1.7k
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.

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 .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.

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" .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.

Source Link
cas
  • 84.7k
  • 9
  • 138
  • 206

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 .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.