#!/bin/bash # # Syntax: rmtex [-h] [-f] [filename [...]] # # Purpose: Removes all auxiliary files created by latex for the given files. # So the files .log, and all files that have the same prefix as # filename and the extension .bak, .aux, .bbl, .blg, .dvi, .lof, # .log, .lot, .toc, .ilg, .ind, .idx, .inx, .ent, .out, .los, .thm, # .shm, .vrb, .nav, .spl, .cb, or .pfg . # If filename is empty then all files with the extensions mentioned # above will be removed. # For security for files for which the corresponding latex file is # no longer present then the program will ask for confirmation of # the removal (except if the extension is .bak). # Use the -f flag to remove those files without asking for # confirmation. # The -h flag shows the help info for this command. # Created: Oct 25, 1991 by Bart De Schutter # Last revised: Dec 22, 2015 by Bart De Schutter # # See http://www.deschutter.info/util/scripts.html for the latest version of # this script. # Status: public # Category: latex confirm=1 while getopts :hf option do case "$option" in h) sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1;; f) confirm=0;; \?) echo >&2 echo >&2 "Unknown option: $OPTARG" echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1;; esac done shift $(($OPTIND-1)) # # Enable @(...|...) globbing. # shopt -q -s extglob \rm .log 2>/dev/null extensions="bak|aux|bbl|blg|dvi|lof|log|lot|toc|ilg|ind|idx|inx|ent|out|los|thm|pfg|spl|cb" beamer_extensions="nav|snm|vrb" # # Determine the files to be removed and remove them. # if [ $# -eq 0 ] then for fil in *.@($extensions|$beamer_extensions) do ext="${fil##*.}" if [[ -e "${fil%.*}.tex" || ( "$ext" == "bak" ) ]] then \rm "$fil" else if [ $confirm -eq 1 ] then \rm -i "$fil" else \rm "$fil" fi fi done else for fname in "$@" do for fil in ${fname%.*}.@(tex.bak|$extensions|$beamer_extensions) do ext="${fil##*.}" if [[ -e "${fil%.*}.tex" || ( "$ext" == "bak" ) ]] then \rm "$fil" else if [ $confirm -eq 1 ] then \rm -i "$fil" else \rm "$fil" fi fi done done fi