Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The following script does the job:

#!/bin/bash
counter=0
for file in *
do
  ((counter++))
  if (( $counter % 2 == 0 ))
  then
    rm "$file"
  fi
done

The following script does the job:

#!/bin/bash
counter=0
for file in *
do
   # Do not delete the script itslef
   if [[ "$(basename -- "$0")" == "$file" ]]; then
      echo "\$file is the filename of the current script."
      continue
   fi
  ((counter++))
  if (( $counter % 2 == 0 ))
  then
    rm "$file"
  fi
done