Skip to content

Instantly share code, notes, and snippets.

@Migweld
Last active August 29, 2015 14:05
Show Gist options
  • Save Migweld/512fda1689f0639d44ff to your computer and use it in GitHub Desktop.
Save Migweld/512fda1689f0639d44ff to your computer and use it in GitHub Desktop.
Loop over directories, regex and remove those with numbers
#!/bin/bash
$PARENTDIR = 'parent_dir here'
#Get a list of dirs/files in parent directory, pipe to egrep and select only directories then pipe to awk to get the 9th field (directory name). Check your shell to make sure $9 is actually the directory name
DIRS=`ls -l $MYDIR | egrep '^d'`| | awk '{print $9}'
# Loop through our directories
for DIR in $DIRS
do
if[[ $DIR =~ regex here ]]; then
`rm -rf ${DIR}`
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment