我有一组文件夹,例如:
/path/to/group1/folder/number123
/path/to/group1/folder/number456
/path/to/group2/folder/number123
/path/to/group2/folder/number456
/path/to/group3/folder/number123
/path/to/group3/folder/number456
我想移动与/path/to/group*/folder/number123
匹配的文件夹
到基本文件夹/path/toOther/
中,以便在移动后看起来像:
/path/to/group1/folder/number456
/path/to/group2/folder/number456
/path/to/group3/folder/number456
/path/toOther/group1/folder/number123
/path/toOther/group2/folder/number123
/path/toOther/group3/folder/number123
是否可以通过移动命令和通配符来完成此操作,还是需要一个以上的划线?
答案 0 :(得分:0)
如果您不介意写几行:
cd /path/to
for f in group*/folder/number123
do
d="/path/toOther/${f%/*}"
mkdir -p "$d"
mv "$f" "$d/."
done
当然,您可以将脚本合并为一行。 (或者当您使用 Up 键调用bash
时,将执行此操作。)