数千のフォルダがある次の種類のフォルダ構造があります。
フォルダ名自体が異なる名前などを持っています。
.test
.test.subfolder
.test.subfolder.subsubfolder
.folder
.folder.one
.folder.two
.folder.one.one
.test
私が達成しなければならないことは次のとおりです。たとえば、フォルダの名前をfromに変更し、test
フォルダ.test.subfolder
がフォルダなしでフォルダ内にあるように.subfolder
移動し、そのフォルダの内側と内側になるようにします。test
.
.test.subfolder.subsubfolder
subfolder
test
subsubfolder
test/subfolder
フォルダが多いので再帰が必要です。フォルダ内のファイルはそのまま残す必要があることを覚えておいてください。
これは可能ですか?
ベストアンサー1
このbashスクリプトは必要なタスクを実行します。
#!/bin/bash
for dir in .*/ ; do
[[ $dir == ./ || $dir == ../ ]] && continue # Skip the special dirs
new=${dir#.} # Remove the dot at the beginning
new=./${new//.//} # Replace dots with slashes, prepend ./
new=${new%/} # Remove the trainling slash
mkdir -p ${new%/*} # Create the parent dir
mv "$dir" "$new" # Move the dir to destination
done