У меня есть сотни тысяч файлов в сотнях каталогов.
Структура каталогов в качестве примера
./main/foo1/bar/*
./main/foo2/bar/*
./main/foo3/bar/*
./main/foo1/ran/*
./main/foo2/ran/*
Для папок, которые имеют каталоги 'панели', я хочу переместить содержание в следующую структуру.
./secondary/bar/foo1/*
./secondary/bar/foo2/*
./secondary/bar/foo3/*
Это может быть выполнено с помощью, находят и mv?
Некоторый небольшой сценарий для достижения этого:
# Set the variables
main="./main"
secondary="./secondary"
foo_depth=3
bar_depth=4
bar_name="bar"
# let * match hidden files
shopt -s dotglob
# Loop through find (which is declared after done)
while IFS= read -r dir; do
# Read names of foo dir
foo=$(printf '%s' "$dir" | cut -d'/' -f $foo_depth)
# mkdir target and mv dir there
target="${secondary}/${bar_name}/${foo}"
mkdir -p "$target"
mv "$dir"/* "$target"
# as you mv the content of bar dir only,
# you may want to remove the full path to that folder
# rmdir -p will do that without deleting anything that is not empty,
# we can ignore the "failed to remove" messages.
[ $? = 0 ] && rmdir -p "${dir}"
done < <(find "$main" -type d -name "$bar_name")
# Turn off dotglob
shopt -u dotglob