是否可以使用wget复制我自己系统中的文件?
我想在我自己的系统中移动/复制大尺寸的文件,我想使用带有-c
开关的wget
命令进行可恢复的传输。 copy( cp
)或move( mv
)命令不为我提供此选项。
是否可以使用wget
将这些文件从一个目录复制到我自己系统中的另一个目录?
是的,但您需要设置Web服务器来提供您需要复制的文件。
尝试这样的事情。 在终端上,启动一个简单的Web服务器:
cd /etc/ python -m SimpleHTTPServer
然后打开另一个终端并执行:
wget http://localhost:8000/passwd
passwd文件将下载到您当前的目录。 您实际上是将它从/ etc /复制到您的主目录。
我不确定你为什么要这样做,但是原则上,正如你所看到的那样,这是可能的。
使用rsync
可能更有意义。 例如:
rsync -aP /source ~/destination
-P
或--partial
标志可防止在发生中断时删除不完整的文件。 如果再次运行相同的命令,将恢复任何未完成的传输。
这样,无需为本地Web服务器而烦恼,这是wget
所需要的。
虽然我强烈推荐rsync
,但您可以在不运行HTTP服务器的情况下使用curl
:
curl -O -C - file:///path/to/some/file
curl
与wget
不同,但是,如果不是更多,那就是强大的。 拥有任何系统总是很方便。
从man curl
:
-C, --continue-at Continue/Resume a previous file transfer at the given offset. Use "-C -" to tell curl to automatically find out where/how to resume the transfer -O, --remote-name Write output to a local file named like the remote file we get.
lftp
可以处理本地文件系统而无需服务器。
lftp
– 复杂的文件传输程序lftp可以处理多种文件访问方法 – ftp,ftps,http,https,hftp,fish,sftp和文件(https和ftps仅在使用GNU TLS或OpenSSL库编译lftp时可用)。
除了类似FTP的协议外,lftp还支持BitTorrent协议作为`torrent’命令。 还支持播种。
参考: man lftp
-
复制sinlge文件:(将
mget
用于多个文件或使用*
joker)lftp -c "get -c file:///
" -
要复制文件夹:
lftp -c "mirror -c file:///
"
首先是-c
用于命令 ,第二个-c
用于尽可能继续 。
对于空间来说,它对我来说既适用于shell,也适用于像Web URL一样的%20
。
这是可能的。 你需要有一个像apache或nginx这样的web服务器。 如果它是apache,复制文件你可以这样做
wget http://localhost/path/to/file/starting/from/var/www/
因为apache服务器的de home目录是/ var / www
使用dd
另一种方式:
- 使用
stat
或ls -l
命令检查目标文件大小 -
复制使用:
dd if=
iflag=skip_bytes skip= oflag=seek_bytes seek= of=
例:
$ 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
它可能是有害的,因为它可以在没有检查的情况下覆盖文件,这里有一个更好的函数来在继续之前检查哈希:
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 "$2" ] then ofpath="$2/`basename \"$1\"`" else ofpath="$2" 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="$1" iflag=count_bytes count=$ofsize 2>/dev/null | md5sum | awk '{print $1}'` #ifhash=`head -c $ofsize "$1" | md5sum | awk '{print $1}'` ofhash=`md5sum "$ofpath" | awk '{print $1}'` # 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 $1 to $ofpath" dd if="$1" iflag=skip_bytes skip=$ofsize oflag=seek_bytes seek=$ofsize of="$ofpath" ;; [nN]) echo -e "Start over...\ncopy $1 to $ofpath" dd if="$1" of="$ofpath" ;; *) echo "Cancelled!" ;; esac }
使用:
ddc
例:
$ 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
还有另一种方式:
-
获取要复制的剩余大小
echo `stat -c "%s"
`-`stat -c "%s" ` | bc -
重定向
tail
输出tail -c
>>
例:
$ echo `stat -c "%s" /boot/grml/u1404_64_d.iso`-`stat -c "%s" /home/user/u1404_64_d.iso` | bc 433049600 $ tail -c 433049600 /boot/grml/u1404_64_d.iso >> /home/user/u1404_64_d.iso $ 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
由于时间似乎对你来说是一个问题 – 另一种方法是使用命令split
将大文件分成更小的部分,例如, split -b 1024m BIGFILE PIECES
来创建1 GByte的部件名为PIECESaa PIECESab … PIECESzz
一旦这些被创建,你会使用像cat PIECES?? >/some/where/else/BIGFILE
cat PIECES?? >/some/where/else/BIGFILE
重建BIGFILE,或者再次,因为你的时间问题:
mkdir done >/somewhere/else/BIGFILE for piece in PIECES?? do cat $piece >>/some/where/else/BIGFILE status=$? if [[ $status -eq 0 ]] then mv $piece done fi done
如果“复制”失败,您可以将文件从./done移回。 并在时间问题解决后再试一次。 – 当wget无法实现时,请将此视为替代方案。 这是我多年来在复制到远程位置时所使用的东西,而像“普通ftp”这样的东西是唯一可以运输的东西。