Outra maneira de usar, usando dd
:
- Verifique o tamanho do arquivo de destino usando
stat
ou ls -l
command
-
Copiar usando:
dd if=<source-file-path> iflag=skip_bytes skip=<dest-file-size> oflag=seek_bytes seek=<dest-file-size> of=<dest-file-path>
Exemplo:
$ ls -l /home/user/u1404_64_d.iso
-rw-rw-r-- 1 user user 147186688 Jan 8 17:01 /home/user/u1404_64_d.iso
$ dd if=/boot/grml/u1404_64_d.iso \
iflag=skip_bytes skip=147186688 oflag=seek_bytes seek=147186688 \
of=/home/user/u1404_64_d.iso
1686798+0 records in
1686798+0 records out
863640576 bytes (864 MB) copied, 15.1992 s, 56.8 MB/s
$ md5sum /boot/grml/u1404_64_d.iso /home/user/u1404_64_d.iso
dccff28314d9ae4ed262cfc6f35e5153 /boot/grml/u1404_64_d.iso
dccff28314d9ae4ed262cfc6f35e5153 /home/user/u1404_64_d.iso
Pode ser prejudicial, já que pode sobrescrever o arquivo sem verificação. Aqui, uma função melhor para verificar o hash antes de continuar:
ddc () {
# enable hash check, need much time to read both files
hashcheck=true
# check destination folder existance or assume it's a file name
if [ -d "" ]
then
ofpath="/'basename \"\"'"
else
ofpath=""
fi
# check destination file existance
if [ ! -f "$ofpath" ]
then
a="n"
else
ofsize='stat -c "%s" "$ofpath"'
# calculate hash
if [ $hashcheck ]
then
ifhash='dd if="" iflag=count_bytes count=$ofsize 2>/dev/null | md5sum | awk '{print }''
#ifhash='head -c $ofsize "" | md5sum | awk '{print }''
ofhash='md5sum "$ofpath" | awk '{print }''
# check hash before cont.
if [ $ifhash == $ofhash ]
then
a="y"
else
echo -e "Files MD5 mismatch do you want to continue:\n(Y) Continue copy, (N) Start over, (Other) Cancel"
read a
fi
else
a="y"
fi
fi
case $a in
[yY])
echo -e "Continue...\ncopy to $ofpath"
dd if="" iflag=skip_bytes skip=$ofsize oflag=seek_bytes seek=$ofsize of="$ofpath"
;;
[nN])
echo -e "Start over...\ncopy to $ofpath"
dd if="" of="$ofpath"
;;
*)
echo "Cancelled!"
;;
esac
}
Uso:
ddc <source-file> <destination-file-or-folder>
Exemplo:
$ ls -l /home/user/u1404_64_d.iso
-rw-rw-r-- 1 user user 241370112 Jan 8 17:09 /home/user/u1404_64_d.iso
$ ddc /boot/grml/u1404_64_d.iso /home/user/u1404_64_d2.iso
Continue...copy /boot/grml/u1404_64_d.iso to /home/user/u1404_64_d.iso
1502846+0 records in
1502846+0 records out
769457152 bytes (769 MB) copied, 13.0472 s, 59.0 MB/s