I salute your quest for knowledge sir! ... this involves setting a loop starting with 0, and check for the file each loop increasing the interger by 1 each cycle.

I'll comment the code for claritity...
Code:
# Start with this X display
display=0

# How many displays should we look for?
cycles=30


while [[ $display -lt $cycles ]]
do


        if [ -f /tmp/.X$display-lock ]; then
          echo "Removing stale X lock file: /tmp/.X$display-lock"
          rm -f /tmp/.X$display-lock >/dev/null
        fi
        # Increase the display number by 1
        display=$[display+1]
done
Now... this will check for lock files for displays 0-29 and remove if found


I thought you was gonna gimme something hard!!! LOL j/k


Take Care,
-Justin
One Mynds Eye