I have a very specific and odd problem to solve. I'm working as a research assistant and I've been producing a ton of figures. In one directory, I dump .pngs to view casually (limited space here) and in the another, I dump .ps and .pdf files to use in latex. It's all automated with matlab. In the .png folder, I've periodically deleted many files I deemed not useful, but the other one is a mess.

How can I tell unix to go through the .ps directory, and for each file, search the .png directory for filenames that match, and then, if they don't match, move the file to a different directory (that I will most likely later delete)?

Are there any commands that could be useful here?


A crude way to do it:

for f in /path/to/PDFs/*.pdf; do
    base=$( basename "$f" .pdf )
    if [ ! -f /path/to/PNGs/"$base".png ]; then
        mv "$f" /path/to/garbage/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.