shell - Rename leaf subdirs with names starting in RR -


i looking rename subdirectories names begin rr , don't have subdirectories of own 'a'

in , if glob wildcard doesn't match print wildcard character itself, e.g. if /somedir/ not have subdirectories, after expansion /somedir/*/ literary equivalent '/somedir/*/'.

so simple bash script find directories without subdirectories , names beginning rr be

#!/bin/bash  shopt -u nullglob  while read -r dir;   [[ $(echo "$dir"/*/) == "$dir/*/" && ${dir##*/} =~ ^'rr' ]] && echo "$dir"  done < <(find . -type d) 

should easy interpolate there, not clear want when have multiple directories matching criteria , can't rename them a?

to rename directories rretcetc a, change following

#!/bin/bash  shopt -u nullglob  while read -r dir;   [[ $(echo "$dir"/*/) == "$dir/*/" && ${dir##*/} =~ ^'rr' ]] && mv -v "$dir" "${dir%/*}/a"  done < <(find . -type d) 

but again note doesn't take account multiple directories matching ^rr in same directory.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -