shell - Rename leaf subdirs with names starting in RR -
i looking rename subdirectories names begin rr , don't have subdirectories of own 'a'
in bash, 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
Post a Comment