将文件从一个目录复制到另一个目录

Copying files from one directory into another

确切地说,我要实现的目标比标题所暗示的要复杂,但我想让它保持合理的简短。我正在尝试执行以下操作; (我对 bash 还是很陌生)

"Take a directory of images whose name is given as an argument, such as the directory XXX, and that produces another directory, whose name is given as another argument, that contains copies of those images, but that are half the size (in linear dimensions)."

我尝试使用以下脚本来做到这一点。

#!/bin/bash

if [ "" != "" ]; then    
    orgdir
fi
if [ "" != "" ]; then    
    cpydir=    
fi    
find "${orgdir}" | while read -r file   
do    
    filesize=$(wc -c <"$orgdir$file")
    dd if=$orgdir of=$cpydir bs=$(($filesize/2))
done

运行 在终端中作为 ./script.sh ./Test ./TestMove 我收到以下错误。

line 11 ./Test./Test: No such file or directory.

我试过只获取 $file 的 wc -c,但上面说 wc 将目录作为标准输入

和;

line 12 ""/2: syntax error: operand expected (error token is """/2")

大概是因为文件大小没有被赋予正确的值?

我也不确定使用 dd 复制文件,一半大小是最好的方法,但我找不到其他方法。

您可以使用安装在大多数 Linux 发行版上的 ImageMagick 套件中的单个命令来完成此操作:

cd "" && mogrify -path "" -resize 50% *.jpg