Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Checks if the bam index files in a directory are newer than their corresponding bam files.
#!/bin/bash
# Directory of the directory you want to scan
DIR="ENTER DIRECTORY HERE"
TOTALBAMS=0
OLDINDEX=0
UNINDEXED=0
for file in $DIR*.bam; do # Iterate over all bam files in given directory
((TOTALBAMS++)) #Count the bam
if [ -f "$file.bai" ]; then # If index exists then check if its newer than bam
if [ "$file" -nt "$file.bai" ]; then
((OLDINDEX++)) # If bam is newer then increment old index counter
fi
else
((UNINDEXED++)) # If index doesn't exist then increment unindexed
fi
done
printf "Total bams in directory: $TOTALBAMS\n"
printf "Old bams: $OLDINDEX\n"
printf "Unindexed bams: $UNINDEXED\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment