[Tex/LaTex] How to clean unused files

cleanupfloatsscripts

I recently edited an existing document to create a new one from it (that is: I copied the whole folder to a new location and started from there).
The early document had a lot of figures, but not all of them were used in the new version.

Now I have a lot of unused files (jpg, pdf, png) under the /fig which I want to get rid of, because they are not called by any \includegraphics command.

Is there a way to list used or unused files?
(I'm not referring to auxiliary files, I'm fine with those.)

Best Answer

I came up with this little script (ran from the root folder of the project):

#!/bin/bash

for image_file in $(ls fig/)
do
if grep $image_file *.log -c > 1
then
        echo "File $image_file is in use."
else
        echo "File $image_file is not in use."
        mv "fig/$image_file" "fig/moved.$image_file" # or any other action
fi
done
Related Question