Last active
August 29, 2015 14:05
-
-
Save Migweld/512fda1689f0639d44ff to your computer and use it in GitHub Desktop.
Loop over directories, regex and remove those with numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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