Recursively execute latexmk -c on folders

451 Views Asked by At

I'd like to execute the command latexmk -c on all of the directories inside a directory, e.g.,

.

./test-dir

The effect is to remove all of the auxiliary files created curing latex compilation.

I've tried using the find command to tell me about the directories and then execute a command, like so:

find -type d -exec latexmk -c \;

But unfortunately, that command only has the effect of removing the auxiliary files in the directory in which I call it, not in the subdirectory (test-dir in this example).

1

There are 1 best solutions below

0
On

I had a very similar problem: I wanted to convert .tex files recursively. The final solution for me was:

find . -name '*.tex' -execdir latexmk -pdf {} \;

The secret here is to use -execdir instead of -exec which executes the command in the directory the file was found. So the solution to your problem is most likely:

find -type d -execdir latexmk -c \;