我在正在使用的文件夹集上进行通配符复制时遇到问题,并且想知道复制这些文件的最佳方法是什么。例如,我的文件夹结构如下:
000
001
001
medium
image1.jpg
original
image1.jpg
thumb
image1.jpg
002
medium
anotherimage2.jpg
original
anotherimage2.jpg
thumb
anotherimage2.jpg
003
medium
someimage3.jpg
original
someimage3.jpg
thumb
someimage3.jpg
002
001
medium
whome_anotherimage_00002.jpg
original
whome_anotherimage_00002.jpg
thumb
whome_anotherimage_00002.jpg
002
medium
crapnotthisagain_067.jpg
original
crapnotthisagain_067.jpg
thumb
crapnotthisagain_067.jpg
我需要做的是使用bash / zsh脚本,或某些命令将图像从每个目录中的原始文件夹递归移动到thumb目录,从而覆盖拇指图像。
到目前为止,使用find
或cp
给我带来了混杂的结果。我越来越接近
find 000/*/*/original/ -type f -name '*.jpg' -exec cp '{}' 000/*/*/thumb/ ';'
,但这只会将文件复制到找到的最后一个thumb
目录中。有没有更好的脚本编写方法?
更新:
运行以下内容:
find 000000/*/*/original/ -type f -name '*.jpg' -exec cp -t 000000/*/*/thumb/ '{}' +
在Mac上把它扔给我
cp: illegal option -- t
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file ... target_directory
cp: illegal option -- t
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file ... target_directory
cp: illegal option -- t
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file ... target_directory
cp: illegal option -- t
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file ... target_directory
cp: illegal option -- t
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file ... target_directory
cp: illegal option -- t
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvXc] source_file ... target_directory
并在ubuntu上:(并且不复制任何内容)
cp: omitting directory ‘000000/001/998/thumb/’
cp: omitting directory ‘000000/001/999/thumb/’
答案 0 :(得分:1)
如何遍历find的结果,然后使用子字符串替换将变量中的“原始”更改为“拇指”:
for i in $(find 000/*/*/original -type f -name '*.jpg'); do cp ${i} ${i/original/thumb}; done