Linux

如何使用 wget bash 腳本一次下載一個文件

  • June 11, 2020

所以我製作了這個 bash 腳本來從網站下載多個文件,我想在後台下載這些文件,因此是“-b 標誌”。

腳本:list.sh

wget -b  -O filename.jpg  www.example.com/image1.jpg
wget -b  -O filename2.jpg  www.example.com/image2.jpg
wget -b  -O filename3.jpg  www.example.com/image4.jpg

如何一次執行一個命令?我想一次下載一個文件,然後在第一個文件完成後,我想下載第二個文件等。

當我執行時./list.sh,它會立即開始下載所有文件。

如果我理解正確,您想在後台執行整個腳本,所以:

#!/bin/bash

wget -O filename.jpg   www.example.com/image1.jpg
wget -O filename2.jpg  www.example.com/image2.jpg
wget -O filename3.jpg  www.example.com/image4.jpg

然後:

$ screen
$ ./script

現在您可以斷開與 Linux 機器的連接,然後返回並檢索會話:

$ screen -r

apt-cache show screen
[...]
Description-en: terminal multiplexer with VT100/ANSI terminal emulation
GNU Screen is a terminal multiplexer that runs several separate "screens" on
a single physical character-based terminal. Each virtual terminal emulates a
DEC VT100 plus several ANSI X3.64 and ISO 2022 functions. Screen sessions
can be detached and resumed later on a different terminal.
.
Screen also supports a whole slew of other features, including configurable
input and output translation, serial port support, configurable logging,
and multi-user support.

引用自:https://unix.stackexchange.com/questions/592290