Find and delete files before a job is submitted to queue

Hello all.

I need some help modifying the following script:

#!/bin/bash
#PBS -l nodes=1:ppn=8,walltime=48:00:00,os=centos53computeA

## To submit type: qsub x.sh

# If not an interactive job (i.e. -I), then cd into the directory where
# I typed qsub.
if [ "$PBS_ENVIRONMENT" != "PBS_INTERACTIVE" ]; then
   if [ -n "$PBS_O_WORKDIR" ]; then
     cd $PBS_O_WORKDIR
   fi
fi

# the input file is typically named something like "gamesjob.inp"
# so the script will be run like "$SCINET_RUNGMS gamessjob 00 8 8"

# load the gamess module if not in .bashrc already
# actually, it MUST be in .bashrc
# module load gamess

# run the program

/scratch/mzd/rungms $NAME 00 8 8 >& $NAME.log

This script is used to submit jobs to a computer cluster to run quantum chemistry programs. I define the $NAME variable in the command line when I run the script.

The trouble is that the program I am running requires that any files with the same name as the file that is submitted must be deleted. That is, it will not overwrite any files with the same name.

That is, I need the script to check in "/scratch/mzd/gamess-scratch/" for any files with the same name as the file that I am submitting ($NAME). If it does find any files, regardless of extension, I need the script to delete them before the job is submitted to the queue. I also need it to check the directory where the input file is for any files that have the same name ($NAME) and delete them as well, also before submitting the job to the queue.

Looking forward to working with you again and thanks in advance.


find /scratch/mzd/gamess-scratch -type f -name ${NAME:-safety_net}\* -exec /bin/rm {} \; 

... that'll do it....

1 Like

Thanks! That is amazing! It works perfectly.

I realize you are probably busy, but could you explain to me each of the parts of the line you sent me?

Best regards.

find in the directory "/scratch/mzd/gamess-scratch" of -type -file with -name ${NAME:-safety_net}\* and execute delete.