如何从所有目录(即Case-r20-c020-t001-da1
,...)复制图像文件夹到维护原始目录名称(例如,...)Case-r20-c020-t001-dan
的新路径中。假设我有一个如下的目录结构;Case-r20-c020-t001-da1
Case-r20-c020-t001-dan
Case-r20-c020-t001-da1/
|____image/ <<<< This is a folder that has some pictures
|______ jpg
|______ png
|____infromation/ <<<< This is a folder.
|_______ text1.txt
|_______ text2.txt
|____ file1.txt
Case-r20-c020-t001-da2/
|____image/
|______ jpg
|______ png
|____infromation/
|_______ text1.txt
|_______ text2.txt
|____ file1.txt
: 。
Case-r20-c020-t001-dan/ <<< n goes from 3,...20.
|____image/
|______ jpg
|______ png
|____infromation/
|_______ text1.txt
|_______ text2.txt
|____ file1.txt
我的初步尝试如下;
for f in Case-r20-c020-t001-da*;do (cp -r images /path/folder*);done
所以,我想将上面的内容复制到一个新的目录中,并且输出必须如下所示;
Case-r20-c020-t001-da1_images/
|____image/
|______ jpg
|______ png
Case-r20-c020-t001-da2_images/
|____image/
|______ jpg
|______ png
: 。
Case-r20-c020-t001-dan_images/
|____image/
|______ jpg
|______ png
我更喜欢当一名指挥官。
任何帮助,将不胜感激。
谢谢,
答案1
作为一个小脚本会更清楚,但这里它被写成一个命令。为了清晰起见,它分为两行:如果您希望将两行连接在一起,请删除反斜杠。
for old in /old/path/Case-r20-c020-t001-da*; \
do new="/new/path/$(basename $old)_images"; mkdir -p "$new" && cp -r "$old/image" "$new/"; done