Well, you could just ignore the rm errors, but that's not elegant :).
Add a function like this to your ~/.bashrc:
function cleantex () {
find . -name "$1*" | grep -vP '.tex$|.pdf$' | while read -r i; do rm "$i"; done
}
You then call it with the (unique) beginning of your filename like so:
$ cleantex mytexfile
It will delete all files in the given directory that start with $file and do not end in .tex or .pdf. The $ makes sure the match is only at the end of the file, the extension. Otherwise it will ignore files like footexfoo.aux because the file name contains tex. You can add as many extensions to ignore as you want:
function cleantex () {
find . -name "$1*" | grep -vP '.tex$|.pdf$|.foo$|.bar$' | while read -r i; do rm "$i"; done
}
If you want to remove these files from within a bash script, you don't really need the function. Just add this line to your script (changing mytexfile to whatever your tex file is called):
find . -name "mytexfile*" | grep -vP '.tex$|.pdf$' | while read -r i; do rm "$i"; done
Finally, if you want to be able to do this for all tex files, whatever their name, use:
find . -name "*.tex" | sed 's/\.tex$//' | while read -r name; do
find . -name "$name"* | grep -vP '.tex$|.pdf$' | while read -r i;
do
rm "$i";
done;
done
-foption tormso that it doesn't complain if there is no file with one of the extensions (rm -f *.aux *.bbl *.blg *.idx *.ilg *.ind *.lof *.log *.lot *.toc…). – Gilles Aug 30 '12 at 1:21-foption. – Sigur Aug 30 '12 at 1:24